Class JsonBuilder


  • public class JsonBuilder
    extends java.lang.Object
    A JsonBuilder is used to parse JSON documents
    Since:
    11
    • 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 a Reader and construct an XdmValue representing its content.
      XdmValue parseJson​(java.lang.String json)
      Parse a JSON input string, supplied as a String and construct an XdmValue representing its content.
      void setLiberal​(boolean liberal)
      Say whether JSON parsing should be liberal.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • 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 a Reader and construct an XdmValue representing its content. The XdmValue will usually be an XdmMap or XdmArray. If the JSON input consists simply of a string, number, or boolean, then the result will be an XdmAtomicValue. If the input is the JSON string "null", the method returns an XdmEmptySequence.

        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 a String and construct an XdmValue representing its content. The XdmValue will usually be an XdmMap or XdmArray. If the JSON input consists simply of a string, number, or boolean, then the result will be an XdmAtomicValue. If the input is the JSON string "null", the method returns an XdmEmptySequence.

        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