Menu

#32 escaping problem

open
nobody
None
5
2012-03-22
2012-03-19
jeroen
No

I am using a function that wraps on top of libjson only to validate and pretty format json. It parses a string of json, and immediately writes it back using json_write_formatted.

I am running into a bug, for which I am not sure if this is happening in the libjson parsing, libjson json_write_formatted, or in the wrapper that I am using. Hopefully we can narrow it down.

The problem happens when the json string contains an escaped characters. For example consider the following valid json:

[ "I said: \"foo!\"" ]

Note that to create this string, depending on your language, you might need to enter something like: "[ \"I said: \\\"foo!\\\"\" ]"

Anyway the string validates as JSON. However, after parsing + prettyprinting it, I get:

[
"I said: \foo!\"
]

You might not be able to see it in your browser, but the \" have been replaced by \001 values. The escaped version of this output looks like this:

"[\n\t\"I said: \\\001foo!\\\001\"\n]"

So the pretty printing has worked (hence the \n and \t, but the \\\" is replaced by \\\001. Could you test if this problem appears in libjson, or if it most likely is due to my wrapper package?

Thanks!

Discussion

  • Jonathan Wallace

    You've found a bug in libjson. I've fixed it and the new version should be ready shortly.

     
  • Jonathan Wallace

    • status: open --> pending
     
  • jeroen

    jeroen - 2012-03-22

    Ok great, looking forward to the fix. Thanks!

     
  • jeroen

    jeroen - 2012-03-22
    • status: pending --> open
     
  • Jonathan Wallace

    Fixed in the version I just released.