Project

General

Profile

Encoding escape sequences in json string

Added by Jim Fred over 10 years ago

If we parse a json string with, say, a backslash, the parser will throw an exception. It's easy enough to escape the backslash when creating the json string but I'm wondering what other characters need to be escaped (like an ampersand) and if there's already a function that provides this encoding. I don't want to re-create a wheel that is likely to exist.

More background behind this question: we're storing parameters in a json configuration file. One parameter on a Windows platform is a path and the backslash, if not escaped, will cause the parser to throw.

I tried searching the forum for 'json encode' or 'json escape' and didn't find anything relevant.

Is there an existing function to encode a json string, adding escape sequences for characters that might cause json parser exceptions?

Thanks!


Replies (3)

RE: Encoding escape sequences in json string - Added by Koen Deforche over 10 years ago

Hey,

In Wt 3.3.1 we've added an encoding function to the Wt::Json namespace.

It's true that you need to encode things --- this is well specified by the JSON spec: http://www.json.org/

Regards,

koen

RE: Encoding escape sequences in json string - Added by Thomas Saquet over 9 years ago

Hello,

I cannot find this encoding function in the Wt::Json namespace. Am I missing it ?

Thank you.

Regards,

Thomas

RE: Encoding escape sequences in json string - Added by Wim Dumon over 9 years ago

The calls to jsStringLiteral in Serialize.C?

Best regards,

Wim.

    (1-3/3)