Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Read and parse json file in Photoshop script (javascript)

Community Beginner ,
Dec 18, 2017 Dec 18, 2017

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!

TOPICS
Actions and scripting
7.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Dec 18, 2017 Dec 18, 2017

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.

Translate
Adobe
LEGEND ,
Dec 18, 2017 Dec 18, 2017

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 18, 2017 Dec 18, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 07, 2018 Feb 07, 2018
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines