xpathxsltxqueryxpath-3.1

fn:parse-json and NUL bytes in XPath


I know that XML doesn't allow NUL bytes in it, but I though that it would somehow work with JSON:

parse-json("""\u0000""") => serialize(map{"method": "json"})

output:

"�"

Is it a limitation of my XPath processor or is it normative?


Solution

  • SaxonJS 2.6 powered XPath 3.1 fiddle gives "\"�\"".

    BaseX fiddle gives "�".

    The spec https://www.w3.org/TR/xpath-functions-31/#func-parse-json says that there is an options map for parse-json with a fallback function and an escape option

    Any characters or codepoints that are not valid XML characters (for example, unpaired surrogates) are passed to the fallback function as described below; in the absence of a fallback function, they are replaced by the Unicode REPLACEMENT CHARACTER (xFFFD).