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

String parsing to JSON in InDesign JavaScript

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

TOPICS
Scripting

Views

2.7K

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 2 Correct answers

Community Expert , Jul 16, 2020 Jul 16, 2020

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.

Votes

Translate

Translate
Engaged , Jul 16, 2020 Jul 16, 2020

Sunil_Yadav1:

The simplest way I know is:

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

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

Votes

Translate

Translate
Community Expert ,
Jul 16, 2020 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

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

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

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

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

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

Copy link to clipboard

Copied

LATEST

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 

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