in reply to Re: Perl structure to Javacript-ready JSON
in thread Perl structure to Javacript-ready JSON

Thanks! I guess my statement was a bit wooly. I'm really trying to do create a javascript literal that I can include like this:
var data = JSON.parse('{"abc":"abc\'abc"}');
.. and must therefore escape the string. I've written code that's essentially like in proposal one. Thanks!

Replies are listed 'Best First'.
Re^3: Perl structure to Javacript-ready JSON
by ikegami (Patriarch) on Nov 26, 2014 at 14:18 UTC
    If you know the JSON is valid, var data = {"abc":"abc'abc"}; is equivalent.
      To expand on this ...

      > If you know the JSON is valid

      ...even if there is a doubt about it's validity, he can wrap your approach into a try/catch expression.

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)