No, Liam, that is a misunderstanding - it *may* be escaped by a preceding , like a handful of other characters, but there is no obligation. However, you are right in pointing out (implicitly) that my assertion was wrong that the information content is changed by the escaping: it is not, they are just alternative representations. Thank you! My experience with JSON is mainly JSON Schema and OpenAPI documents. There I have NEVER seen slashes escaped. They use URLs and JSON Pointer a lot, which would look very awkward with / everywhere.
I still think that the choice of representation should be the same when moving from JSON to XML nodes, or back. There is a strong argument to stick with the unescaped variants in the XML representation: as the information content retrieved from those elements treats / as two characters, not as an escaped /. In other words: json:doc('foo.json')//bar would potentially yield a different sequence of characters than encoded by the source JSON. This seems to mean that any use of JSON data fetched from the XML representation would have to be preceded by a transformation performed by the application (replacing / with /, etc.).
Kind regards,Hans-Jürgen
Am Sonntag, 21. März 2021, 18:08:14 MEZ hat Liam R. E. Quin liam@fromoldbooks.org Folgendes geschrieben:
On Sun, 2021-03-21 at 09:42 +0000, Hans-Juergen Rennau wrote:
PPS: Please do not even dream of thinking about considering or not excluding to change the parsers behaviour which leaves the slash as it is - otherwise you cannot use JSON information in XML representation without wiggling around - e.g. follow links, imagine. It's the serializer who gets it wrong.
The JSON spec requires / to be escaped.
string = quotation-mark *char quotation-mark
char = unescaped / escape ( %x22 / ; " quotation mark U+0022 %x5C / ; \ reverse solidus U+005C %x2F / ; / solidus U+002F %x62 / ; b backspace U+0008 %x66 / ; f form feed U+000C %x6E / ; n line feed U+000A %x72 / ; r carriage return U+000D %x74 / ; t tab U+0009 %x75 4HEXDIG ) ; uXXXX U+XXXX
escape = %x5C ; \
quotation-mark = %x22 ; "
unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
Liam