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
2 Correct answers
Yes ofcourse,
Here is the link for the file.
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.
Sunil_Yadav1:
The simplest way I know is:
var newJson = eval("(" + jsonString + ")");
But of course JSON.stringify() can't be use without a library.
Copy link to clipboard
Copied
Hi,
Did you include or evaluate JSON.jsx file? JSON is not in built in Indesign javascript.
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
Copy link to clipboard
Copied
Yes ofcourse,
Here is the link for the file.
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.
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
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.
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

