public class JSONUtils extends Object
| Constructor and Description |
|---|
JSONUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
convertTo2DArray(org.json.JSONObject grandParent,
String parentKey,
String elementKey)
Converts an array of mixed objects into a 2D JSONArray.
|
static void |
convertToJSONArray(org.json.JSONObject grandParent,
String parentKey,
String childKey)
Omits the key `childKey` and puts its contents directly under the `parentKey` as a JSONArray.
|
static String |
createMissingAttrMessage(org.json.JSONException ex)
This is a helper function to create a message for a JSONException that is formatted as suitable for display to a user.
|
static boolean |
equalsIgnoreCase(org.json.JSONArray ja1,
org.json.JSONArray ja2)
Checks for deep equality of two JSONArrays, resolving elements that are JSONObjects or JSONArrays recursively.
|
static boolean |
equalsIgnoreCase(org.json.JSONObject jo1,
org.json.JSONObject jo2)
Checks for deep equality of two JSONObjects, resolving elements that are JSONObjects or JSONArrays recursively.
|
static org.json.JSONArray |
getNNJArray(org.json.JSONArray parent,
int index) |
static org.json.JSONArray |
getNNJArray(org.json.JSONObject parent,
Object key) |
static org.json.JSONObject |
getnnJObject(org.json.JSONArray parent,
int index) |
static org.json.JSONObject |
getNNJObject(org.json.JSONObject parent,
Object key) |
static org.json.JSONObject |
loadModelJSON(String path)
Loads Model configuration from a JSON file.
|
static org.json.JSONObject |
loadModelXML(String path)
Loads Model configuration from an XML file and converts it into suitable JSONObject.
|
static org.json.JSONObject |
toJSONObject(Object[][] array)
Converts a 2D Object array into a JSONObject.
|
static <T> List<T> |
toList(org.json.JSONArray jarray,
Class<T> classType)
Converts JSONArray to a List of provided type.
|
static void |
traverse(Object o,
Consumer<Object> action)
Applies the provided action to the provided object.
|
static void |
wrapArrayElements(org.json.JSONArray parent,
String wrapperName)
Wraps all elements of the provided JSONArray into JSONObjects that each contains the element under the provided key.
|
public static org.json.JSONObject toJSONObject(Object[][] array)
array - Basic 2D Object array representation of the mappublic static String createMissingAttrMessage(org.json.JSONException ex)
ex - Exception that has the message to convertpublic static <T> List<T> toList(org.json.JSONArray jarray, Class<T> classType)
T - type of objects expected to be in the listjarray - JSONArray arrayclassType - Class of items to be in the listpublic static void convertTo2DArray(org.json.JSONObject grandParent,
String parentKey,
String elementKey)
throws org.json.JSONException
grandParent - JSONObject that should contain the 2D array (in the example - object `table`)parentKey - the key of the 2D array in grandParent (in the example - "probs")elementKey - the elementKey to be omitted (in the example - "cell")org.json.JSONException - on failurepublic static void convertToJSONArray(org.json.JSONObject grandParent,
String parentKey,
String childKey)
throws org.json.JSONException
grandParent - JSONObject containing `parentKey`, in the example - object networkparentKey - - the key under which to put the resulting array, in the example - "nodes"childKey - - the key to omit (and wrap contents into array if necessary), in the example - "node"org.json.JSONException - on failurepublic static void wrapArrayElements(org.json.JSONArray parent,
String wrapperName)
parent - the array to wrap elements ofwrapperName - the key name under which to wrap each elementpublic static org.json.JSONObject loadModelXML(String path) throws ModelException, org.json.JSONException
path - XML file pathModelException - if failed to read from fileorg.json.JSONException - if XML structure is invalid or inconsistentpublic static org.json.JSONObject loadModelJSON(String path) throws ModelException, org.json.JSONException
path - JSON file pathModelException - if failed to read from fileorg.json.JSONException - if JSON structure is invalid or inconsistentpublic static boolean equalsIgnoreCase(org.json.JSONObject jo1,
org.json.JSONObject jo2)
jo1 - a JSONObjectjo2 - a second JSONObject to compare to jo1equalsIgnoreCase(JSONArray, JSONArray),
equalsJSONComponents(Object, Object)public static boolean equalsIgnoreCase(org.json.JSONArray ja1,
org.json.JSONArray ja2)
ja1 - a JSONArrayja2 - another JSONArray to compare withequalsIgnoreCase(JSONObject, JSONObject),
equalsJSONComponents(Object, Object)public static org.json.JSONObject getnnJObject(org.json.JSONArray parent,
int index)
public static org.json.JSONObject getNNJObject(org.json.JSONObject parent,
Object key)
public static org.json.JSONArray getNNJArray(org.json.JSONObject parent,
Object key)
public static org.json.JSONArray getNNJArray(org.json.JSONArray parent,
int index)
public static void traverse(Object o, Consumer<Object> action)
o - object to apply action to and potentially traverseaction - action to applyCopyright © 2020. All rights reserved.