Copy link to clipboard
Copied
Hi All,
We are intermittently getting JSON is undefined alert while converting object to string using JSON.stringify()
It gets resolved by resetting Premiere Pro preference: Configure preference settings in Premiere Pro
We want to know why and when JSON object is not available in the jsx file. Is there any way to prevent this alert?
Premiere Pro Version: 9.0.0
Extension Type: Panel
Thanks & Regards,
Meet Tank
meett9325076 wrote
We are intermittently getting JSON is undefined alert while converting object to string using JSON.stringify()
It gets resolved by resetting Premiere Pro preference: Configure preference settings in Premiere Pro
We want to know why and when JSON object is not available in the jsx file. Is there any way to prevent this alert?
The default ExtendScript environment does not support JSON. You can verify this yourself by opening the ExtendScript Toolkit and looking for it in the Data
...Copy link to clipboard
Copied
Why are you targeting such an antique version of PPro?
The ExtendScript JSON object is provided NOT by ExtendScript, but by Adobe's own panels. I'll bet you can come up with a working implementation, bringing that JSON support into your panel.
Copy link to clipboard
Copied
Bruce Bullis​, I have found an example: https://www.davidebarranca.com/2014/02/html-panels-tips-5-passing-objects-from-jsx-to-html-json/ In which: "Mind you, ExtendScript doesn’t support JSON natively so the original library must be included"
I think we should not rely on third party javascript library to add support of JSON in the extend script.
Questions:
Thanks,
Meet
Copy link to clipboard
Copied
We have no plans to attempt to add JSON support to ExtendScript. We recommend doing any JSON-related work in a panel's CEP/JavaScript layer.
Copy link to clipboard
Copied
Thank you Bruce Bullis. We need to convert object to string from jsx itself as a return value. Can we use third party JSON object only when existing JSON (provided by Adobe's panel) is not available?
Thanks,
Meet
Copy link to clipboard
Copied
I'm not sure; I've never done any testing of competing JSON modules.
If you're including your own JSON handling, you could conceivably name it JSON_Meet or something to avoid any potential collisions, right?
Copy link to clipboard
Copied
meett9325076 wrote
We are intermittently getting JSON is undefined alert while converting object to string using JSON.stringify()
It gets resolved by resetting Premiere Pro preference: Configure preference settings in Premiere Pro
We want to know why and when JSON object is not available in the jsx file. Is there any way to prevent this alert?
The default ExtendScript environment does not support JSON. You can verify this yourself by opening the ExtendScript Toolkit and looking for it in the Data Browser. By default, it won't be there. It probably will be once you attach to a running version of Premiere Pro. This is because many of Adobe's UI screens (including, it seems, something related to the preference settings flow) actually load their own JSON library into the application's ExtendScript context.
When you run ExtendScript in an application you are actually doing so in a shared context. All panels share the same global context. If you're able to use JSON by default, this is likely because some other Adobe-provided panel was run before yours was and included JSON. If you actually look at the globally loaded JSON objects in the ExtendScript environment, you'll see that there are actually several (JSON and JSON3). This is because different Adobe panels load different JavaScript JSON libraries. My guess is that different teams within Adobe are responsible for different panels and are free to choose their own.
You appear to have found yourself in a situation where you were able to start up Premiere Pro without other panels loading first. To resolve this, include your own third-party JSON library in your project (there are several free ones available, including the previously linked JSON3). Well-formatted ones automatically test for the pre-existence of the JSON APIs and will only install if one doesn't exist. We use this one.
To install it we have the following in our main JSX script:
//@include ../lib/json2.jsx
(Note that we renamed the .js file to .jsx, even though it isn't necessary.)
Effectively, you need to Polyfill the ExtendScript context with any APIs not included in the ECMAScript 3 standard.
Copy link to clipboard
Copied
Thanks sberic. We need a minified version of https://github.com/douglascrockford/JSON-js/blob/master/json2.js. Where can we find that?
Copy link to clipboard
Copied
meett9325076 wrote
We need a minified version of https://github.com/douglascrockford/JSON-js/blob/master/json2.js. Where can we find that?
Did a quick Google search and found this CDNJS link. See here for the minified file, but note that it does reference the sourcemap (which is also available in the CDNJS link).