public final class JSONCompareUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
allJSONArrays(org.json.JSONArray array)
Returns whether all elements in
array are JSONArray instances. |
static boolean |
allJSONObjects(org.json.JSONArray array)
Returns whether all elements in
array are JSONObject instances. |
static boolean |
allSimpleValues(org.json.JSONArray array)
Returns whether all of the elements in the given array are simple values.
|
static Map<Object,org.json.JSONObject> |
arrayOfJsonObjectToMap(org.json.JSONArray array,
String uniqueKey)
Converts the provided
JSONArray to a Map of JSONObjects where the key of each object
is the value at uniqueKey in each object. |
static String |
findUniqueKey(org.json.JSONArray expected)
Searches for the unique key of the
expected JSON array. |
static String |
formatUniqueKey(String key,
String uniqueKey,
Object value) |
static <T> Map<T,Integer> |
getCardinalityMap(Collection<T> coll)
Creates a cardinality map from
coll. |
static Set<String> |
getKeys(org.json.JSONObject jsonObject)
Collects all keys in
jsonObject. |
static Object |
getObjectOrNull(org.json.JSONArray jsonArray,
int index)
Returns the value present in the given index position.
|
static boolean |
isSimpleValue(Object o)
Returns whether the given object is a simple value: not
JSONObject and not JSONArray. |
static boolean |
isUsableAsUniqueKey(String candidate,
org.json.JSONArray array)
Looks to see if candidate field is a possible unique key across a array of objects.
|
static List<Object> |
jsonArrayToList(org.json.JSONArray expected)
Converts the given
JSONArray to a list of Objects. |
static String |
qualify(String prefix,
String key) |
public static Map<Object,org.json.JSONObject> arrayOfJsonObjectToMap(org.json.JSONArray array, String uniqueKey) throws org.json.JSONException
JSONArray to a Map of JSONObjects where the key of each object
is the value at uniqueKey in each object.array - the JSON array to convertuniqueKey - the key to map the JSON objects toJSONObjects from arrayorg.json.JSONException - JSON parsing errorpublic static String findUniqueKey(org.json.JSONArray expected) throws org.json.JSONException
expected JSON array.expected - the array to find the unique key oforg.json.JSONException - JSON parsing errorpublic static boolean isUsableAsUniqueKey(String candidate, org.json.JSONArray array) throws org.json.JSONException
Looks to see if candidate field is a possible unique key across a array of objects. Returns true IFF:
candidate - is usable as a unique key if every element in thearray - is a JSONObject having that key, and no two values are the same.org.json.JSONException - JSON parsing errorpublic static List<Object> jsonArrayToList(org.json.JSONArray expected) throws org.json.JSONException
JSONArray to a list of Objects.expected - the JSON array to convertexpected arrayorg.json.JSONException - JSON parsing errorpublic static Object getObjectOrNull(org.json.JSONArray jsonArray, int index) throws org.json.JSONException
jsonArray - the JSON array to get value fromindex - index of object to retrieveorg.json.JSONException - JSON parsing errorpublic static boolean allSimpleValues(org.json.JSONArray array)
throws org.json.JSONException
array - the JSON array to iterate through onarray are simple valuesorg.json.JSONException - JSON parsing errorisSimpleValue(Object)public static boolean isSimpleValue(Object o)
JSONObject and not JSONArray.o - the object to inspecto is a simple valuepublic static boolean allJSONObjects(org.json.JSONArray array)
throws org.json.JSONException
array are JSONObject instances.array - the array to inspectorg.json.JSONException - JSON parsing errorpublic static boolean allJSONArrays(org.json.JSONArray array)
throws org.json.JSONException
array are JSONArray instances.array - the array to inspectorg.json.JSONException - JSON parsing errorpublic static Set<String> getKeys(org.json.JSONObject jsonObject)
jsonObject.jsonObject - the JSONObject to get the keys ofpublic static <T> Map<T,Integer> getCardinalityMap(Collection<T> coll)
coll.T - the type of elements in the input collectioncoll - the collection of items to convertCopyright © 2023. All rights reserved.