Copy link to clipboard
Copied
Hi everybody,
I have to export psd layers to files and I managed to automate the related 'save as' process with a simple script. Depending on its name, each layer is saved as a new file in the right folder, and the whole thing works pretty fine.
In order to make it work within different projects and with different naming conventions, I thought to make the script read sort of a database file - i.e. a json file - containing the destination folder path and the naming rules. So that I can easily customize the db file instead of looking through the whole script and find/replace things.
Unfortunately I didn't succeed in parsing the json file: this is a little beyond my knowledge. I tried to make some tests following the accurate and useful instructions found in other threads, but I'm not skilled enough to understand what I'm doing wrong.
Could anybody help me with a more dummy-proof explanation of how to correctly edit and parse a json file in javascript?
Thank you in advance!
1 Correct answer
json is javascript so this should work:
The json file
var data = {
name:"loic"
}
The main script
$.evalFile ( Folder.desktop+"/data.json" );
alert( data.name );
If the json is stringified, then you would need to use json2 library:
https://github.com/douglascrockford/JSON-js/blob/master/json2.js
Hope that helps.
Explore related tutorials & articles
Copy link to clipboard
Copied
Post your code, or that important (working part) that we can test it and find solution. It seems there is no need .json usage. It can be obtained other easy way as well...
Copy link to clipboard
Copied
json is javascript so this should work:
The json file
var data = {
name:"loic"
}
The main script
$.evalFile ( Folder.desktop+"/data.json" );
alert( data.name );
If the json is stringified, then you would need to use json2 library:
https://github.com/douglascrockford/JSON-js/blob/master/json2.js
Hope that helps.
Copy link to clipboard
Copied
I'm really sorry for the late reply. Unfortunately some bad inconvenients had kept me from working on this tool but l'm on it again now!
First of all, thank you very much for your answers!
I tried the structure suggested by Loic and it seems to work pretty fine!
In my case evalFile works perfectly, and I don't need json2.js.
Sorry for my script, kukurykus, I should have posted it. I'm going to do it as soon as possible, at least for completing the discussion.
Thank you!

