Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Perl structure to Javacript-ready JSON

by Jeppe (Monk)
on Nov 26, 2014 at 08:21 UTC ( #1108428=note: print w/replies, xml ) Need Help??


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 ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1108428]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2022-01-21 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?