3

Escape single quote(\') is not allowed in JSON specification but allowd in some Java's JSON implementations, explained clearly here: jQuery single quote in JSON response (first answer).

I've tried jackson and Gson, both are allowed escape single quote.

Here is my question:

  1. Besides escape single quote, Is there any other difference between Java implementation of JSON and JSON specification?

  2. Is there any Java implementation which is totally the same with JSON specification exists?

Community
  • 1
  • 1
tuoxie
  • 81
  • 4
  • 1
    https://www.mkyong.com/java/json-simple-example-read-and-write-json/ ? It's what I use – Tschallacka Apr 11 '17 at 08:32
  • 1
    Why do such slight nuances in implementation matter to you? – Tim Biegeleisen Apr 11 '17 at 08:33
  • 3
    @TimBiegeleisen probaly to be able to depend on the spec as is. To know what data to expect and what not. When an implementation deviates from a spec I expect detailed documentation as to what has changed, because you might have to account for it in code. If you sell loaves of bread, and I give you a dollar, I expect a loaf of bread. If I instead get a baguette, which technically will be bread too when looked at it as a nuance, I will still be reacting poorly to the strange switch, or not. it depends on what i'm gonna do with the bread. – Tschallacka Apr 11 '17 at 08:37
  • 1
    Typical guidelines for specifications are to be liberal in what you accept, but to be very strict when generating. In this case, I would accept any character being escaped when parsing (I cannot immediately see where this might cause ambiguities), but would only generate JSON that escaped those few characters allowed in the specification. – Phylogenesis Apr 11 '17 at 08:59
  • I make a mistake about jackson, it's not allowed escape single quote... – tuoxie Apr 11 '17 at 10:11
  • And Gson is much more flexible than I expected, it seems allowed all single blackslash in json string and will delete it if the character followed is not allowed in json specification (as @Phylogenesis said), but jackson and json.simple seems strictly follow JSON specification – tuoxie Apr 11 '17 at 10:13

0 Answers0