Highlighted

String parsing to JSON in InDesign JavaScript

Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

I am posting this for my concern, may be this has already been asked in any other posts or forum, but unfortunately I am not able to find.

I am struggling to parse string to JSON using InDesign JavaScript.

/////////////

var jsonString = '{"include_selected_image":false,"image_auto_numbering_type":"0"}';

var newJson = JSON.parse(jsonString);

/////////////////////

This is giving me exception : Error: JSON is undefined

 

Thanks in advance

Sunil

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

Yes ofcourse,

Here is the link for the file.

JSON2.jsx 

 

You can evalaute the file

$.evalFile(File('filePath'))

or just include using

# include "json2.jsx"

 

Let us know if it helps to resolve your problem.

Topics

Scripting

Views

116

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

String parsing to JSON in InDesign JavaScript

Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

I am posting this for my concern, may be this has already been asked in any other posts or forum, but unfortunately I am not able to find.

I am struggling to parse string to JSON using InDesign JavaScript.

/////////////

var jsonString = '{"include_selected_image":false,"image_auto_numbering_type":"0"}';

var newJson = JSON.parse(jsonString);

/////////////////////

This is giving me exception : Error: JSON is undefined

 

Thanks in advance

Sunil

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

Yes ofcourse,

Here is the link for the file.

JSON2.jsx 

 

You can evalaute the file

$.evalFile(File('filePath'))

or just include using

# include "json2.jsx"

 

Let us know if it helps to resolve your problem.

Topics

Scripting

Views

117

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
Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

Hi,

Did you include or evaluate JSON.jsx file? JSON is not in built in Indesign javascript.

Best regards

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...
Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

No charu,

I do not have this file "JSON.jsx" with me, can you provide me with that?

Can you guide me more into that?

 

Thanks

Sunil

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...
Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

Yes ofcourse,

Here is the link for the file.

JSON2.jsx 

 

You can evalaute the file

$.evalFile(File('filePath'))

or just include using

# include "json2.jsx"

 

Let us know if it helps to resolve your problem.

Best regards

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...
Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

Thanks Charu Rajput,

This is a great help with very quick response.

This has helped me a lot & hopefully others who are looking for this solution.

 

Thank You

Sunil

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...
Engaged ,
Jul 16, 2020

Copy link to clipboard

Copied

Sunil_Yadav1:

The simplest way I know is:

var newJson = eval("(" + jsonString + ")");

But of course JSON.stringify() can't be use without a library. 

Yusuke S.

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...
Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

Thanks Yasuke for your answer as well.

I was stuck parsing JSON, Charu Rajput has provided JSON.jsx as well with perfect solution.

 

As suggested by Yasuke :

var newJson = eval("(" + jsonString + ")");

will evaluate the JSON but JSON.stringify() can be utilized after including JSON.jsx

 

Big Thanks to both of you.

 

Thanks

Sunil 

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