public class JsonUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static com.jayway.jsonpath.JsonPath |
compileJsonPath(String jsonPath)
Compiles the given JSONPath.
|
static boolean |
isEmpty(Object object)
Null-safe method that evaluates the specified object for emptiness.
|
static Object |
readJsonPath(org.codehaus.jettison.json.JSONObject json,
String jsonPath)
Gets a value that matches the given JSONPath.
|
static Object |
readJsonPath(org.codehaus.jettison.json.JSONObject json,
String jsonPath,
boolean extractSingleElement)
Gets a value that matches the given JSONPath.
|
static org.codehaus.jettison.json.JSONArray |
toJSONArray(Object object)
Converts an object to a
JSONArray. |
static org.codehaus.jettison.json.JSONObject |
toJSONObject(Object object)
Converts an object to a
JSONObject. |
static List<Object> |
toList(org.codehaus.jettison.json.JSONArray jsonArray)
Converts a
JSONArray into a Java-standard List. |
public static boolean isEmpty(Object object)
For example, an empty JSONObject ("{ }") or JSONArray ("[ ]") evaluates
to true.
Null references also evaluate to true.
object - the Object to be validatedtrue if the Object is null or emptypublic static com.jayway.jsonpath.JsonPath compileJsonPath(String jsonPath)
jsonPath - the JSONPath to be validatedJsonPath objectpublic static Object readJsonPath(org.codehaus.jettison.json.JSONObject json, String jsonPath)
json - a JSON object input datajsonPath - the JSONPath to be evaluatednull if no match
was found. If the JSON is empty or null, the same object will be returned.public static Object readJsonPath(org.codehaus.jettison.json.JSONObject json, String jsonPath, boolean extractSingleElement)
jsonPath - the JSONPath to be validatedjson - a JSON object input dataextractSingleElement - a flag indicating whether the method should return the
single value of a JSONArray instead of the array itself,
provided that the length of the returnable array is equal
to one.jsonPath over the json object;public static org.codehaus.jettison.json.JSONObject toJSONObject(Object object) throws org.codehaus.jettison.json.JSONException
JSONObject.
If the specified input is a String, then it will be parsed as a JSONObject.
If the specified input is null, then an empty JSONObject ("{ }") will
be returned.
If the specified input is already a JSONObject, then the same object will be
returned.
object - the object to be convertedJSONObjectorg.codehaus.jettison.json.JSONException - in case of errors converting into JSONObject (for
example, if there is a syntax error in the source string).public static org.codehaus.jettison.json.JSONArray toJSONArray(Object object) throws org.codehaus.jettison.json.JSONException
JSONArray.
If the specified input is a String, then it will be parsed as a JSONArray.
If the specified input is null, then an empty JSONArray ("[ ]") will be
returned.
If the specified input is already a JSONArray, then the same object will be
returned.
object - the object to be convertedJSONArrayorg.codehaus.jettison.json.JSONException - in case of errors converting into JSONArray (for example, if
there is a syntax error in the source string).Copyright © 2021. All rights reserved.