Copy link to clipboard
Copied
Hi Bruce,
I will soon be working on an HTML5 panel that will be receiving some JSON data through a URL call.
Is there a way to pass this JSON data to the javascript portion of the panel, so I can access all the objects?
thanks,
Kelly
1 Correct answer
Thomas is right.
This may help, with passing JSON back from ExtendScript, to JavaScript:
HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.
Also relevant:
ExtendScript ToolkitFrancois Tarlier's Blog | Francois Tarlier's blog
Copy link to clipboard
Copied
Kelly,
you can simply put all Javascript (that is required to call the JSON object) inside of the main index.html file. It works just like in a standard browser. Once you received the JSON obj, you can pass it around in your HTML or Javascript code as you like.
Thomas
Copy link to clipboard
Copied
Thomas is right.
This may help, with passing JSON back from ExtendScript, to JavaScript:
HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.
Also relevant:
ExtendScript ToolkitFrancois Tarlier's Blog | Francois Tarlier's blog
Copy link to clipboard
Copied
Okay thanks. I'll check these to links out. However, I guess maybe I worded my question wrong in the first place.
Can you also pass the JSON object from the html file to ExtendScript?
thanks,
Kelly
Copy link to clipboard
Copied
I'm not sure; no one's ever asked me about handling JSON, within ExtendScript. Usually goes the other way.
Copy link to clipboard
Copied
Yes you can pass data over to Extendscript. If your JSON is an object, you would have to stringify it first. Example:
var my_json = {foo:"bar"};
var csInterface = new CSInterface();
csInterface.evalScript("$.your_extendscript_function( " + JSON.stringify(my_json) + " )");
Thomas
Copy link to clipboard
Copied
Thanks everyone for your input.
I went with Thomas' suggestion to stringify.
Unfortunately I had to do a few tricks to parse it back into an array of objects. (A few splits and a few replaces)
But in the end I was able to get what I needed.
Copy link to clipboard
Copied
Grab this file: GitHub - douglascrockford/JSON-js: JSON in JavaScript
In a .jsx file:
#include "json2.js"
var item = JSON.parse(info)
var stringItem = JSON.stringify(jsonObject)

