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

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

7.9K

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.

Votes

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.

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
Explorer ,
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.

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

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
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:)

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

Copy link to clipboard

Copied

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-...

 

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
Community Beginner ,
Oct 05, 2023 Oct 05, 2023

Copy link to clipboard

Copied

Hello, I had the JSON undefined error as well and have embedded the json2.js file into my Premiere.jsx.  This solved my problem however I would rather link to the json2.js file instead of embedding the whole thing in my .jsx
To link files in html, I would do something like this... 

<script src="./main.js"></script>
To link files in Java or C++ I would use #import or #include

How do you link the JSON.js files in Premiere.jsx???

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
Explorer ,
Nov 01, 2023 Nov 01, 2023

Copy link to clipboard

Copied

LATEST

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!

 

Screenshot 2023-11-01 at 4.40.35 PM.png

 

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