Skip to main content
TimSx
Inspiring
June 14, 2018
Answered

JSON is undefined error

  • June 14, 2018
  • 2 replies
  • 12477 views

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?

This topic has been closed for replies.
Correct answer Tomas Sinkunas

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.

2 replies

Prazzle
Known Participant
November 1, 2023

Can anyone help me with this? I am not working with JSON file. I am simply trying to upload a 5MB pdf to a job site (their maximum allowed is 10MB) and I am getting this message. Can anyone tell me why I am getting this message? It seems to have nothing to do with my file or the website. Thanks!

 

 

Tomas Sinkunas
Tomas SinkunasCorrect answer
Legend
June 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.

Inspiring
February 9, 2022

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.

Tomas B. aka Tom10
Inspiring
February 10, 2022

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