Class JSONValue

java.lang.Object
net.minidev.json.JSONValue

public class JSONValue extends Object
JSONValue is the helper class In most of case you should use those static method to user JSON-smart The most commonly use method are parse(String) toJSONString(Object)
Author:
Uriel Chemouni <[email protected]>
  • Field Details

    • COMPRESSION

      public static JSONStyle COMPRESSION
      Global default compression type
    • defaultWriter

      public static final JsonWriter defaultWriter
      Serialisation class Data
    • defaultReader

      public static final JsonReader defaultReader
      deserialisation class Data
  • Constructor Details

    • JSONValue

      public JSONValue()
  • Method Details

    • parse

      public static Object parse(InputStream in)
      Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      See Also:
    • parse

      public static Object parse(byte[] in)
      Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      See Also:
    • parse

      public static <T> T parse(InputStream in, Class<T> mapTo)
      Parse input json as a mapTo class mapTo can be a bean
      Since:
      2.0
    • parse

      public static Object parse(Reader in)
      Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      See Also:
    • parse

      public static <T> T parse(byte[] in, Class<T> mapTo)
      Parse input json as a mapTo class mapTo can be a bean
      Since:
      2.0
    • parse

      public static <T> T parse(Reader in, Class<T> mapTo)
      Parse input json as a mapTo class mapTo can be a bean
      Since:
      2.0
    • parse

      public static <T> T parse(Reader in, T toUpdate)
      Parse input json as a mapTo class mapTo can be a bean
      Since:
      2.0
    • parse

      protected static <T> T parse(Reader in, JsonReaderI<T> mapper)
      Parse input json as a mapTo class
      Since:
      2.0
    • parse

      public static <T> T parse(String in, Class<T> mapTo)
      Parse input json as a mapTo class mapTo can be a bean
      Since:
      2.0
    • parse

      public static <T> T parse(InputStream in, T toUpdate)
      Parse input json as a mapTo class mapTo can be a bean
      Since:
      2.0
    • parse

      public static <T> T parse(String in, T toUpdate)
      Parse input json as a mapTo class mapTo can be a bean
      Since:
      2.0
    • parse

      protected static <T> T parse(byte[] in, JsonReaderI<T> mapper)
      Parse input json as a mapTo class
      Since:
      2.0
    • parse

      protected static <T> T parse(String in, JsonReaderI<T> mapper)
      Parse input json as a mapTo class
      Since:
      2.0
    • parse

      public static Object parse(String s)
      Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      See Also:
    • parseKeepingOrder

      public static Object parseKeepingOrder(Reader in)
      Parse Json input to a java Object keeping element order
      Parameters:
      in - json source
      Returns:
      a OrderedMap preserving field order.
      Since:
      1.0.6.1
    • parseKeepingOrder

      public static Object parseKeepingOrder(String in)
      Parse Json input to a java Object keeping element order
      Parameters:
      in - json source
      Returns:
      a OrderedMap preserving field order.\
      Since:
      1.0.6.1
    • compress

      public static String compress(String input, JSONStyle style)
      Reformat Json input keeping element order
      Parameters:
      input - text to parse
      style - parse options
      Returns:
      json string
      Since:
      1.0.6.2
    • compress

      public static String compress(String input)
      Compress Json input keeping element order
      Parameters:
      input - text to parse
      Since:
      1.0.6.1 need to be rewrite in 2.0
    • uncompress

      public static String uncompress(String input)
      Compress Json input keeping element order
      Parameters:
      input - text to parse
      Since:
      1.0.6.1
    • parseWithException

      public static Object parseWithException(byte[] in) throws IOException, ParseException
      Parse JSON text into java object from the input source.
      Parameters:
      in - source to parse
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      Throws:
      IOException
      ParseException
      See Also:
    • parseWithException

      public static Object parseWithException(InputStream in) throws IOException, ParseException
      Parse JSON text into java object from the input source.
      Parameters:
      in - source to parse
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      Throws:
      IOException
      ParseException
      See Also:
    • parseWithException

      public static Object parseWithException(Reader in) throws IOException, ParseException
      Parse JSON text into java object from the input source.
      Parameters:
      in - source to parse
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      Throws:
      IOException
      ParseException
      See Also:
    • parseWithException

      public static Object parseWithException(String input) throws ParseException
      Parse JSON text into java object from the input source.
      Parameters:
      input - string to parse
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      Throws:
      ParseException - if input in invalid
      See Also:
    • parseWithException

      public static <T> T parseWithException(String in, Class<T> mapTo) throws ParseException
      Parse input json as a mapTo class
      Parameters:
      in - source to parse
      mapTo - destination type, mapTo can be a javabean
      Returns:
      unserialized object of type mapTo
      Throws:
      ParseException
      Since:
      2.0
    • parseStrict

      public static Object parseStrict(Reader in) throws IOException, ParseException
      Parse valid RFC4627 JSON text into java object from the input source.
      Parameters:
      in - source to parse
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      Throws:
      IOException
      ParseException
      See Also:
    • parseStrict

      public static Object parseStrict(String s) throws ParseException
      Parse valid RFC4627 JSON text into java object from the input source.
      Parameters:
      s - source to parse
      Returns:
      Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
      Throws:
      ParseException
      See Also:
    • isValidJsonStrict

      public static boolean isValidJsonStrict(Reader in) throws IOException
      Check RFC4627 Json Syntax from input Reader
      Returns:
      if the input is valid
      Throws:
      IOException
    • isValidJsonStrict

      public static boolean isValidJsonStrict(String s)
      check RFC4627 Json Syntax from input String
      Returns:
      if the input is valid
    • isValidJson

      public static boolean isValidJson(Reader in) throws IOException
      Check Json Syntax from input Reader
      Returns:
      if the input is valid
      Throws:
      IOException
    • isValidJson

      public static boolean isValidJson(String s)
      Check Json Syntax from input String
      Returns:
      if the input is valid
    • writeJSONString

      public static void writeJSONString(Object value, Appendable out) throws IOException
      Encode an object into JSON text and write it to out.

      If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.

      Throws:
      IOException
      See Also:
    • remapField

      public static <T> void remapField(Class<T> type, String jsonFieldName, String javaFieldName)
      Remap field from java to json, useful to avoid protected keyword in java class.
      Parameters:
      type - type to alter
      jsonFieldName - field name in json
      javaFieldName - field name in java
      Since:
      2.1.1
    • registerWriter

      public static <T> void registerWriter(Class<?> cls, JsonWriterI<T> writer)
      Register a serializer for a class.
    • registerReader

      public static <T> void registerReader(Class<T> type, JsonReaderI<T> mapper)
      register a deserializer for a class.
    • writeJSONString

      public static void writeJSONString(Object value, Appendable out, JSONStyle compression) throws IOException
      Encode an object into JSON text and write it to out.

      If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.

      Throws:
      IOException
      See Also:
    • toJSONString

      public static String toJSONString(Object value)
      Encode an object into JSON text and write it to out.

      If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.

      Parameters:
      value - object to serialize
      Returns:
      json string
      See Also:
    • toJSONString

      public static String toJSONString(Object value, JSONStyle compression)
      Convert an object to JSON text.

      If this object is a Map or a List, and it's also a JSONAware, JSONAware will be considered firstly.

      DO NOT call this method from toJSONString() of a class that implements both JSONAware and Map or List with "this" as the parameter, use JSONObject.toJSONString(Map) or JSONArray.toJSONString(List) instead.

      Parameters:
      value - to serialize
      compression - serialisation options
      Returns:
      JSON text, or "null" if value is null or it's an NaN or an INF number.
      See Also:
    • escape

      public static String escape(String s)
    • escape

      public static String escape(String s, JSONStyle compression)
      Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).
      Parameters:
      s - string to escape
      compression - compression options
      Returns:
      escaped string
    • escape

      public static void escape(String s, Appendable ap)
    • escape

      public static void escape(String s, Appendable ap, JSONStyle compression)