yes, Martins solution works as expected. But in my opinion there are used too many conversions

xml -> json string -> map/array -> serialized json

There are no technical problems with the escaped slashes. There just was a complaint, that the results are not good readable (we are using a json format for error reporting). We probably will leave the XQuery implementation as is and adapt the consumer of the JSON.

Thanks all for your input.

Johannes


Am 27.02.2020 um 09:23 schrieb Christian Grün:
Hi Johannes,

As far as I can judge, Martin’s solution looks like the most compact
one to me that you can find; the escaping of special characters
(including slashes) is part of the official specification, and
fn:xml-to-json provides no options to disable escaping for specific or
for all characters.

Please note that the serialization of our own json functions may
change as well in future versions. It’s likely that we’ll further
align the escaping of characters with the official spec.

Out of interest: most JSON client implementations should be able to
interpret and decode backslashes, as it’s fixed part of the JSON
format [1]. Why would you like to remove the slashes in advance?

Greetings from/to the Lake of Konstanz,
Christian

[1] https://www.json.org/json-en.html



<map xmlns="http://www.w3.org/2005/xpath-functions";>
      <string key="url">http://some.url/path/to/somewhere</string></map>
=> xml-to-json()
=> parse-json()
=> serialize(map { 'method': 'json', 'use-character-maps' : map { '/' :
'/' }})


gives the JSON with unescaped slashes for me in BaseX and Saxon. Not
sure there is a more compact way, either BaseX specific or for XQuery in
general, to achieve this. I am sure Christian can tell you.




Reply via email to