Package net.minidev.json
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 methode to user JSON-smart The most commonly use methode areparse(String)toJSONString(Object)- Author:
- Uriel Chemouni
-
-
Field Summary
Fields Modifier and Type Field Description static JSONStyleCOMPRESSIONGlobal default compression typestatic JsonWriterdefaultWriter
-
Constructor Summary
Constructors Constructor Description JSONValue()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringcompress(String s)Compress Json input keeping element orderstatic Stringcompress(String input, JSONStyle style)Reformat Json input keeping element orderstatic Stringescape(String s)static voidescape(String s, Appendable ap)static voidescape(String s, Appendable ap, JSONStyle compression)static Stringescape(String s, JSONStyle compression)Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).static booleanisValidJson(Reader in)Check Json Syntax from input Readerstatic booleanisValidJson(String s)Check Json Syntax from input Stringstatic booleanisValidJsonStrict(Reader in)Check RFC4627 Json Syntax from input Readerstatic booleanisValidJsonStrict(String s)check RFC4627 Json Syntax from input Stringstatic Objectparse(byte[] in)Parse JSON text into java object from the input source.static Objectparse(byte[] in, int offset, int length)Parse JSON text into java object from the input source.static Objectparse(InputStream in)Parse JSON text into java object from the input source.static Objectparse(Reader in)Parse JSON text into java object from the input source.static Objectparse(String s)Parse JSON text into java object from the input source.static ObjectparseKeepingOrder(byte[] in)Parse Json input to a java Object keeping element orderstatic ObjectparseKeepingOrder(byte[] in, int offset, int length)Parse Json input to a java Object keeping element orderstatic ObjectparseKeepingOrder(InputStream in)Parse Json input to a java Object keeping element orderstatic ObjectparseKeepingOrder(Reader in)Parse Json input to a java Object keeping element orderstatic ObjectparseKeepingOrder(String in)Parse Json input to a java Object keeping element orderstatic ObjectparseStrict(byte[] s)Parse valid RFC4627 JSON text into java object from the input source.static ObjectparseStrict(byte[] s, int offset, int length)Parse valid RFC4627 JSON text into java object from the input source.static ObjectparseStrict(InputStream in)Parse valid RFC4627 JSON text into java object from the input source.static ObjectparseStrict(Reader in)Parse valid RFC4627 JSON text into java object from the input source.static ObjectparseStrict(String s)Parse valid RFC4627 JSON text into java object from the input source.static ObjectparseWithException(byte[] in)Parse JSON text into java object from the input source.static ObjectparseWithException(byte[] in, int offset, int length)Parse JSON text into java object from the input source.static ObjectparseWithException(InputStream in)Parse JSON text into java object from the input source.static ObjectparseWithException(Reader in)Parse JSON text into java object from the input source.static ObjectparseWithException(String s)Parse JSON text into java object from the input source.static voidSAXParse(InputStream input, ContentHandler handler)Parse Json Using SAX event handlerstatic voidSAXParse(Reader input, ContentHandler handler)Parse Json Using SAX event handlerstatic voidSAXParse(String input, ContentHandler handler)Parse Json Using SAX event handlerstatic StringtoJSONString(Object value)Encode an object into JSON text and write it to out.static StringtoJSONString(Object value, JSONStyle compression)Convert an object to JSON text.static Stringuncompress(String s)Compress Json input keeping element orderstatic voidwriteJSONString(Object value, Appendable out)Encode an object into JSON text and write it to out.static voidwriteJSONString(Object value, Appendable out, JSONStyle compression)Encode an object into JSON text and write it to out.
-
-
-
Field Detail
-
COMPRESSION
public static JSONStyle COMPRESSION
Global default compression type
-
defaultWriter
public static JsonWriter defaultWriter
-
-
Method Detail
-
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
- Since:
- 1.0.9-2
- See Also:
JSONParser.parse(Reader),parseWithException(Reader)
-
parse
public static Object parse(byte[] in, int offset, int length)
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
- Since:
- 1.1.2
- See Also:
JSONParser.parse(Reader),parseWithException(Reader)
-
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
- Since:
- 1.0.9-2
- See Also:
JSONParser.parse(Reader),parseWithException(Reader)
-
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:
JSONParser.parse(Reader),parseWithException(Reader)
-
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:
JSONParser.parse(String),parseWithException(String)
-
parseKeepingOrder
public static Object parseKeepingOrder(byte[] in)
Parse Json input to a java Object keeping element order- Since:
- 1.0.9-2
-
parseKeepingOrder
public static Object parseKeepingOrder(byte[] in, int offset, int length)
Parse Json input to a java Object keeping element order- Since:
- 1.1.2
-
parseKeepingOrder
public static Object parseKeepingOrder(InputStream in)
Parse Json input to a java Object keeping element order- Since:
- 1.0.9-2
-
parseKeepingOrder
public static Object parseKeepingOrder(Reader in)
Parse Json input to a java Object keeping element order- Since:
- 1.0.6.1
-
parseKeepingOrder
public static Object parseKeepingOrder(String in)
Parse Json input to a java Object keeping element order- Since:
- 1.0.6.1
-
SAXParse
public static void SAXParse(InputStream input, ContentHandler handler) throws ParseException, IOException
Parse Json Using SAX event handler- Throws:
ParseExceptionIOException- Since:
- 1.0.9-2
-
SAXParse
public static void SAXParse(Reader input, ContentHandler handler) throws ParseException, IOException
Parse Json Using SAX event handler- Throws:
ParseExceptionIOException- Since:
- 1.0.6.2
-
SAXParse
public static void SAXParse(String input, ContentHandler handler) throws ParseException
Parse Json Using SAX event handler- Throws:
ParseException- Since:
- 1.0.6.2
-
compress
public static String compress(String input, JSONStyle style)
Reformat Json input keeping element order- Since:
- 1.0.6.2
-
compress
public static String compress(String s)
Compress Json input keeping element order- Since:
- 1.0.6.1
-
uncompress
public static String uncompress(String s)
Compress Json input keeping element order- 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.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- Since:
- 1.0.9-2
- See Also:
JSONParser
-
parseWithException
public static Object parseWithException(byte[] in, int offset, int length) throws IOException, ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- Since:
- 1.1.2
- See Also:
JSONParser
-
parseWithException
public static Object parseWithException(InputStream in) throws IOException, ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- Since:
- 1.0.9-2
- See Also:
JSONParser
-
parseWithException
public static Object parseWithException(Reader in) throws IOException, ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- See Also:
JSONParser
-
parseWithException
public static Object parseWithException(String s) throws ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException- See Also:
JSONParser
-
parseStrict
public static Object parseStrict(InputStream in) throws IOException, ParseException
Parse valid RFC4627 JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- Since:
- 1.0.9-2
- See Also:
JSONParser
-
parseStrict
public static Object parseStrict(Reader in) throws IOException, ParseException
Parse valid RFC4627 JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- See Also:
JSONParser
-
parseStrict
public static Object parseStrict(String s) throws ParseException
Parse valid RFC4627 JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException- See Also:
JSONParser
-
parseStrict
public static Object parseStrict(byte[] s) throws ParseException
Parse valid RFC4627 JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException- See Also:
JSONParser
-
parseStrict
public static Object parseStrict(byte[] s, int offset, int length) throws ParseException
Parse valid RFC4627 JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException- Since:
- 1.1.2
- See Also:
JSONParser
-
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.
-
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.
-
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.
-
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.
- Returns:
- JSON text, or "null" if value is null or it's an NaN or an INF number.
- See Also:
JSONObject.toJSONString(Map),JSONArray.toJSONString(List)
-
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).
-
escape
public static void escape(String s, Appendable ap)
-
escape
public static void escape(String s, Appendable ap, JSONStyle compression)
-
-