Skip to main content
Inspiring
July 9, 2020
Answered

Can't manage to JSON.parse() in my CEP panel

  • July 9, 2020
  • 1 reply
  • 501 views

Hi,

i'm writing a CEP panel for indesign, and as i couldn't manage to JSON.parse my data string, i erased my code to test JSON with these 2 short lines in my index.js file :

var jsonTest=JSON.parse("{'test':'ok'}");
alert(jsonTest.test);

Could someone tell me why this doesn't give me any result ?

script is running (i tested with an alert() before the variable declaration) but

alert(jsonTest.test) isn't triggered.

(JSON is written in "variable color"... It migth be a clue as it should be green like any other global object... when i write it, it is green for a sec before it turns blue... Conflict somewhere ?)

 

Thanks fo reading.

    This topic has been closed for replies.
    Correct answer Durad

    Ok i found out what was going on.

    My JSON file wasn't valid, due to Marc Autret's json.jsx lave() function, which was outputting \xE8 for "è".

    I don't know what i did wrong, as many people seems to use json.jsx without reporting any issue.

    But i finally replaced json.jsx with json2.js, and got a valid JSON.

    Will i encounter any other problem... We'll see !

     

    1 reply

    DuradAuthorCorrect answer
    Inspiring
    July 21, 2020

    Ok i found out what was going on.

    My JSON file wasn't valid, due to Marc Autret's json.jsx lave() function, which was outputting \xE8 for "è".

    I don't know what i did wrong, as many people seems to use json.jsx without reporting any issue.

    But i finally replaced json.jsx with json2.js, and got a valid JSON.

    Will i encounter any other problem... We'll see !