Skip to main content
Silly-V
Legend
October 30, 2018
Question

empty array in JSON`

  • October 30, 2018
  • 2 replies
  • 1172 views

I experienced something which I am wondering if anyone else had as well: when passed as evalScript argument, a JSON object containing an empty array is causing the error "Unterminated string constant at Line 1".

I have my evalScript statement with the syntax : evalScript("myFunc('" + JSON.stringify(myArg) + "')");

While I'm expecting it to work when the object myArg has an empty array among its properties, it throws the above-mentioned error.

Is this normal?

I'm okay with just changing an empty array to null and writing statements to watch for that in those situations where an array is expected. But hopefully it's just something I'm messing up.

This topic has been closed for replies.

2 replies

Inspiring
November 1, 2018

Hi,

try with escape() function..

evalScript("myFunc('" + escape(JSON.stringify(myArg))+ "')")

and use unescape() in jsx

Trevor:
Legend
October 30, 2018

Why don't you log or at least alert the output of the script?

myScript = "myFunc('" + JSON.stringify(myArg) + "')";

alert(myScript)

evalScript(alert)

You're see exactly what's going on then.

If that doesn't help then you can use try catch

Silly-V
Silly-VAuthor
Legend
October 30, 2018

It apparently made an empty array have a return line between the brackets when I did something which may have involved parsing a previously-stringified JSON object which I stored inside of an artwork's notes in Illustrator.