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

ExtendScripts JSON object is suddenly undefined?

Enthusiast ,
Sep 22, 2016 Sep 22, 2016

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?!

TOPICS
SDK

Views

2.7K

Translate

Translate

Report

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

Enthusiast , Sep 22, 2016 Sep 22, 2016

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.

Votes

Translate

Translate
Participant ,
Sep 22, 2016 Sep 22, 2016

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

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 22, 2016 Sep 22, 2016

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.

Votes

Translate

Translate

Report

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
Adobe Employee ,
Sep 23, 2016 Sep 23, 2016

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!

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 23, 2016 Sep 23, 2016

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?

Votes

Translate

Translate

Report

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
Adobe Employee ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

LATEST

Pretty sure it's our Libraries panel, but that's speculation on my part. As you've already found; don't rely on it.

Votes

Translate

Translate

Report

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