Copy link to clipboard
Copied
I've been passing data pretty fluently back and forth between a custom HTML5 panel and ExtendScript, making use of JSON.stringify
All of a sudden, today the JSON object is coming up as undefined in the ExtendScript context.
I know it has worked, and now it doesn't. Why on earth?!
1 Correct answer
Was considering the manually-implemented stringify, but being able to use JSON.parse & .stringify was enormously convenient.
Found Douglas Crockford's very handy JS library: GitHub - douglascrockford/JSON-js: JSON in JavaScript​ via this forum thread: Re: HTML5 Panel passing JSON data to javascript
The Crockford file generates a JSON obj when it doesn't exists. So far working great.
Copy link to clipboard
Copied
I´m not sure since which PPro version the JSON object is supported in Extendscript but I never trusted it. I definitely recommend to stringify your data manually.
I used to do it this way:
var obj = '{';
obj += '"type":"bin",';
obj += '"age":"'+current_age+'",';
obj += '"name":"'+encodeURIComponent(item.name)+'"';
obj += '}';
For arrays it´s much simpler:
var arr = ["one", "two", "three"];
var string = '['+arr.join(",")+']';
Definitely encode strings that you don´t have control over.
Also, please check if you can implement a listener coding pattern which uses CSXSEvents. On Extendscript you pass it a stringified object and get a parsed object back on the HTML5 listener side. This avoids JSON.parse() on the HTML side.
I hope this helps.
Thomas
Copy link to clipboard
Copied
Was considering the manually-implemented stringify, but being able to use JSON.parse & .stringify was enormously convenient.
Found Douglas Crockford's very handy JS library: GitHub - douglascrockford/JSON-js: JSON in JavaScript​ via this forum thread: Re: HTML5 Panel passing JSON data to javascript
The Crockford file generates a JSON obj when it doesn't exists. So far working great.
Copy link to clipboard
Copied
JSON isn't reliably available in ExtendScript, because it's provided by another panel.
Also, ExtendScript is NOT NOT NOT JavaScript, but if Crockford's code works, great!
Copy link to clipboard
Copied
So with the Crockford JSON up and running, problem solved.
Regarding...
Bruce Bullis wrote:
JSON isn't reliably available in ExtendScript, because it's provided by another panel.
So that explains its ghostly arrivals and departures. Just out of curiousity, what panel is it that's making it available one minute and then not the next?
Copy link to clipboard
Copied
Pretty sure it's our Libraries panel, but that's speculation on my part. As you've already found; don't rely on it.

