JSON is undefined error

Participant ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

I've use JSON.parse() and JSON.stringify() numerous times. For some very odd reason, whenever I try to use JSON now, an error is thrown saying that JSON is undefined.

This is a toy example to showcase how strange this is:

var jstr = JSON.stringify({obj:12}); // JSON is undefined error here

var obj = JSON.parse(jstr);

alert(obj);

In AE Scripting guide, it says that it uses  ECMA-262  specification, which includes support for JSON.

Has anyone else experience this bizarreness? Is there a fix or should I just bring in my own JSON functions?

TOPICS
Scripting

Views

3.8K

Likes

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

Advocate , Jun 14, 2018 Jun 14, 2018
By defaul, JSON is undefined in ESTK.If you happen to stumble upon defined JSON, that means some other script/panel is poluting global scope and injecting JSON object globally. If im not misstaken, Libraries are doing that.If you want to work with JSON you should import it explicetly to your script. Dent rely on cases when soe other tool injects it globally.Most of AE scripters use this library to import JSON GitHub - douglascrockford/JSON-js: JSON in JavaScript Hope that helps.

Likes

Translate

Translate
Advocate ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

By defaul, JSON is undefined in ESTK.

If you happen to stumble upon defined JSON, that means some other script/panel is poluting global scope and injecting JSON object globally. If im not misstaken, Libraries are doing that.

If you want to work with JSON you should import it explicetly to your script. Dent rely on cases when soe other tool injects it globally.

Most of AE scripters use this library to import JSON GitHub - douglascrockford/JSON-js: JSON in JavaScript

Hope that helps.

Likes

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
Community Beginner ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

I don't know what any of that means from the accepted answer. I'm an animator, not a computer science guy, and I usually code in python for Maya so a lot of this is over my head.  I wrote a js script for our studio to automate a bunch of tasks in which one of the functions does this:

parsedData = JSON.parse(data)
For myself and most of our artists, we don't have a problem.  But one artist is getting the error that JSON is undefined.  I assume this is unique to his After Effects installation or some other module preventing his After Effects application from utilizing JSON.   We are all using AE 18.4.0 or later.  Both JSON.jsx and json2.js are in his Support Files directory for After Effects.
Please tell me how to fix.
Thanks.

Likes

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
Participant ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

If you want to have library as an additional file along the script, copy all from this page and paste into your script. It should work.

https://github.com/douglascrockford/JSON-js/blob/master/json2.js

Likes

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
Participant ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Sorry, if you DON'T want library as a separate file, do what I wrote above inside your own script file:)

Likes

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
Community Beginner ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

LATEST

ok, so I've discovered that (for my own computer anyway) if I open After Effects normally, I can run the script and it executes without a problem--meaning that it doesn't throw the JSON is undefined error. 
However, if I open AE through a subprocess and run the script automatically*, it throws the error that JSON is undefined. 
I copied that entire thing into ( from https://github.com/douglascrockford/JSON-js/blob/master/json2.js) into my script.  This seems to have no effect.  Deleting that code block has no effect.  What am I missing?

*https://community.adobe.com/t5/after-effects-discussions/need-to-run-a-js-script-automatically-from-...

 

Likes

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