Package net.sf.saxon.s9api
Class JsonBuilder
java.lang.Object
net.sf.saxon.s9api.JsonBuilder
A
JsonBuilder
is used to parse JSON documents- Since:
- 11
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Ask whether JSON parsing should be liberal.Parse a JSON input string, supplied as aReader
and construct anXdmValue
representing its content.Parse a JSON input string, supplied as aString
and construct anXdmValue
representing its content.void
setLiberal
(boolean liberal) Say whether JSON parsing should be liberal.
-
Constructor Details
-
JsonBuilder
-
-
Method Details
-
setLiberal
public void setLiberal(boolean liberal) Say whether JSON parsing should be liberal. When this option is selected, the JSON parser tolerates a number of deviations from the JSON specification.Specifically, liberal mode currently allows:
- Trailing commas in array and object literals
- More flexibility for numeric literals (for example, exponential notation and leading '+')
- Invalid escape sequences in character strings
- Unquoted strings, provided they follow the syntax of an XML NMTOKEN
- Parameters:
liberal
- - true if parsing is to be liberal, false if it is to be strict
-
isLiberal
public boolean isLiberal()Ask whether JSON parsing should be liberal. When this option is selected, the JSON parser tolerates a number of deviations from the JSON specification, for example trailing commas in an array or object literal.- Returns:
- true if parsing is to be liberal, false if it is to be strict
-
parseJson
Parse a JSON input string, supplied as aReader
and construct anXdmValue
representing its content. TheXdmValue
will usually be anXdmMap
orXdmArray
. If the JSON input consists simply of a string, number, or boolean, then the result will be anXdmAtomicValue
. If the input is the JSON string "null", the method returns anXdmEmptySequence
.The method follows the rules of the
fn:parse-json()
function when called with default options.- Parameters:
jsonReader
- supplies the input JSON as a stream of characters- Returns:
- the result of parsing the JSON input. This will be an
XdmItem
in all cases except where the input JSON text is the string "null". - Throws:
SaxonApiException
- if the JSON input is invalid, or if the reader throws an IOException- Since:
- 11
-
parseJson
Parse a JSON input string, supplied as aString
and construct anXdmValue
representing its content. TheXdmValue
will usually be anXdmMap
orXdmArray
. If the JSON input consists simply of a string, number, or boolean, then the result will be anXdmAtomicValue
. If the input is the JSON string "null", the method returns anXdmEmptySequence
.The method follows the rules of the
fn:parse-json()
function when called with default options.- Parameters:
json
- supplies the input JSON as a string- Returns:
- the result of parsing the JSON input
- Throws:
SaxonApiException
- if the JSON input is invalid- Since:
- 11
-