1

I am using flexjson. I would like to find out how to set the JSONSerializer to use single-quotes rather than double-quotes to flank string values when serializing.

I am open to using another Java JSON library.

Note: I am not interested in advice on how to use double-quotes to accommodate my requirements.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Blessed Geek
  • 21,058
  • 23
  • 106
  • 176

1 Answers1

0

If it turns out that no existing library supports this out of the box, I'd probably copy the few classes of org.json and modify the quote method.

Reto Höhener
  • 5,419
  • 4
  • 39
  • 79
  • org.json is a very simple to use library good to learn JSON. But for practical use it is too simplistic and with low performance. It is also not so easy there to parse complex classes. And taking any library and changing its code is an extreme, last resort option, usually not recommended. (I have done it at some point for Hibernate code, but only after exostive research that lead me to conclusion that this was my only option. So, I don't think this is a good solution. -1 for the solution, please don't take it personally – Michael Gantman Dec 23 '20 at 16:45
  • It's used heavily in [practice](https://mvnrepository.com/artifact/org.json/json). Since single quotes are not valid json, it might be impossible to find a library that supports it out of the box. I agree this is a last resort if you cannot find a library that supports it. But it might still be much faster to implement than other workarounds. – Reto Höhener Dec 23 '20 at 16:53
  • See my answer. There is a library that supports it out of the box - it is Jackson JSON also known as FasterXML – Michael Gantman Dec 23 '20 at 17:01
  • Ok, I'll delete when I see the example. – Reto Höhener Dec 23 '20 at 17:02
  • Like I said, it works out of the box, no config required. – Michael Gantman Dec 23 '20 at 17:03
  • What does that mean? I would hope that out-of-the box would write double quotes, no? – Reto Höhener Dec 23 '20 at 17:04
  • It means that if you use that library it will parse JSON with either single-quotes or double-quotes. In other words, it treats single quotes as valid in JSON. For example it will parse JSON {'Hello':'World'} the same as {"Hello":"World"} – Michael Gantman Dec 23 '20 at 17:07
  • But the question is about writing (serialization). – Reto Höhener Dec 23 '20 at 17:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226360/discussion-between-michael-gantman-and-reto-hohener). – Michael Gantman Dec 23 '20 at 17:27