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.