Package net.sf.saxon.s9api
Class JsonBuilder
- java.lang.Object
-
- net.sf.saxon.s9api.JsonBuilder
-
public class JsonBuilder extends java.lang.Object
AJsonBuilder
is used to parse JSON documents- Since:
- 11
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsonBuilder(Configuration config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isLiberal()
Ask whether JSON parsing should be liberal.XdmValue
parseJson(java.io.Reader jsonReader)
Parse a JSON input string, supplied as aReader
and construct anXdmValue
representing its content.XdmValue
parseJson(java.lang.String json)
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 Detail
-
JsonBuilder
protected JsonBuilder(Configuration config)
-
-
Method Detail
-
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
public XdmValue parseJson(java.io.Reader jsonReader) throws SaxonApiException
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
public XdmValue parseJson(java.lang.String json) throws SaxonApiException
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
-
-