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

Unable to get the data from JSON to illustrator through javascript

Participant ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

Hi,

I am trying to get the data from JSON into Illustrator.

For that i am trying with my Javascript coding is,

#include json2.js

var jsonFile = File.openDialog("Select the JSON");

var data = JSON.parse(jsonFile);

alert(data.id);

 

My JSON coding is,

{

  "id": 638455,

  "description": "1234"

 }

I got an error as "throw new SyntaxError("JSON.parse")". Can you please check and do the needful to get the data from JSON to illustrator through script.

Note: I am unable to upload the json2.js here, i have downloaded and used the json2.jx from the github.

 

Thanks

Asuvath

 

 

 

 

TOPICS
Scripting

Views

462

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

Community Expert , Oct 21, 2020 Oct 21, 2020

You need to read the file and pass the string to the parse method, try the following

#include "json2.js"
var jsonFile = File.openDialog("Select the JSON")
jsonFile.open("r")
var data = JSON.parse(jsonFile.read());
alert(data.id);

-Manan

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

You need to read the file and pass the string to the parse method, try the following

#include "json2.js"
var jsonFile = File.openDialog("Select the JSON")
jsonFile.open("r")
var data = JSON.parse(jsonFile.read());
alert(data.id);

-Manan

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 ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

LATEST

Thanks lot Manan. Its working Fine.

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