fn:parse-json
This function takes as input a string in JSON format and parses it typically returning a map or array.
parse-json($json-text as xs:string?) ➔ item()?
Arguments | |||
| $json-text | xs:string? | The JSON input to be parsed |
Result | item()? |
parse-json($json-text as xs:string?, $options as map(*)) ➔ item()?
Arguments | |||
| $json-text | xs:string? | The JSON input to be parsed |
| $options | map(*) | Parsing options |
Result | item()? |
Namespace
http://www.w3.org/2005/xpath-functions
Links to W3C specifications
XPath 3.1 Functions and Operators
Notes on the Saxon implementation
Available since Saxon 9.7. The parsing options recognized are
'liberal':true()|false()
,
'duplicates':'reject'|'use-first'|'retain'
,
'escape':true()|false()
, 'fallback':(function)
. For full
details see the specification. Use of the fallback
option requires Saxon-PE
or Saxon-EE.
When liberal=true()
, the following extensions to the JSON grammar are accepted:
- Within arrays and objects, trailing commas are ignored: for example
[1,2,3,]
is treated as[1,2,3]
. (This does not apply if the array or object is otherwise empty, so[,]
and{,}
are not accepted.) - Within numeric literals, anything accepted as an XPath numeric literal
is accepted (for example, leading plus signs, leading zeroes, absent fractional part,
absent integer part: but not
INF
orNaN
). - Within a string literal, if backslash is followed by a character
X
and\X
is not a recognized JSON escape sequence, then it is treated as representing the characterX
. - The key of a key-value pair in an object can be written without quotation marks provided it takes the
form of an XML NCName, and is not "true", "false", or "null". For example,
{a:3, b:4}
is accepted.