Highlighted

Unable to get the data from JSON to illustrator through javascript

Community Beginner ,
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

 

 

 

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

34

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

Unable to get the data from JSON to illustrator through javascript

Community Beginner ,
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

 

 

 

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

35

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
Oct 21, 2020 0
Adobe Community Professional ,
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

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
Reply
Loading...
Oct 21, 2020 1
Asuvath LATEST
Community Beginner ,
Oct 21, 2020

Copy link to clipboard

Copied

Thanks lot Manan. Its working Fine.

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
Reply
Loading...
Oct 21, 2020 0
Resources