public class Flat extends Object
{
"key1": {
"keyA": "valueI"
},
"key2": {
"keyB": "valueII"
},
"key3": { "a": { "b": { "c": 2 } } }
}
After:
{
"key1.keyA": "valueI",
"key2.keyB": "valueII",
"key3.a.b.c": 2
}
The library can do the reverse operation as well: unflatten.| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_DELIMITER
The default delimiter is used by methods that do not specify a delimiter.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
flatten(org.json.JSONObject jsonObject)
This method flattens the given JSON object.
|
static String |
flatten(org.json.JSONObject jsonObject,
String delimiter)
This method flattens the given JSON object.
|
static String |
flatten(String jsonString)
This method flattens the string representation of the JSON object.
|
static String |
flatten(String jsonString,
String delimiter)
This method flattens the string representation of the JSON object.
|
static org.json.JSONObject |
flattenToJSONObject(org.json.JSONObject jsonObject)
This method flattens the given JSON object.
|
static org.json.JSONObject |
flattenToJSONObject(org.json.JSONObject jsonObject,
String delimiter)
This method flattens the string representation of the JSON object.
|
static org.json.JSONObject |
flattenToJSONObject(String jsonString)
This method flattens the string representation of the JSON object.
|
static org.json.JSONObject |
flattenToJSONObject(String jsonString,
String delimiter)
This method flattens the string representation of the JSON object.
|
static String |
unflatten(org.json.JSONObject flatJsonObject)
This method takes a flattened JSON object and returns it to
the conventional format.
|
static String |
unflatten(org.json.JSONObject flatJsonObject,
String delimiter)
This method takes a flattened JSON object and returns it to
the conventional format.
|
static String |
unflatten(String flatJsonString)
This method takes the string representation of a flattened JSON object
and returns it to the conventional format.
|
static String |
unflatten(String flatJsonString,
String delimiter)
This method takes the string representation of a flattened JSON object
and returns it to the conventional format.
|
static org.json.JSONObject |
unflattenToJSONObject(org.json.JSONObject flatJsonObject)
This method takes a flattened JSON object and returns it to
the conventional format.
|
static org.json.JSONObject |
unflattenToJSONObject(org.json.JSONObject flatJsonObject,
String delimiter)
This method takes a flattened JSON object and returns it to
the conventional format.
|
static org.json.JSONObject |
unflattenToJSONObject(String flatJsonObject)
This method takes the string representation of a flattened JSON object
and returns it to the conventional format.
|
static org.json.JSONObject |
unflattenToJSONObject(String flatJsonString,
String delimiter)
This method takes the string representation of a flattened JSON object
and returns it to the conventional format.
|
public static final String DEFAULT_DELIMITER
public static String flatten(org.json.JSONObject jsonObject) throws org.json.JSONException
jsonObject - the JSON object to flattenorg.json.JSONExceptionpublic static String flatten(String jsonString) throws org.json.JSONException
jsonString - the string representation of the JSON object.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static String flatten(org.json.JSONObject jsonObject, String delimiter) throws org.json.JSONException
Flat.flatten(new JSONObject("\"key1": { \"nested1\" : 1, \"nested2\" : 2 }}"), "@");
will generate:
{
"key1@nested1" : 1
"key1@nested2" : 2
}
instead of the default:
{
"key1.nested1" : 1
"key1.nested2" : 2
}
jsonObject - the JSON object to flattendelimiter - the delimiter to use when joining the keys.org.json.JSONExceptionpublic static String flatten(String jsonString, String delimiter) throws org.json.JSONException
Flat.flatten("\"key1": { \"nested1\" : 1, \"nested2\" : 2 }}", "@");
will generate:
{
"key1@nested1" : 1
"key1@nested2" : 2
}
instead of the default:
{
"key1.nested1" : 1
"key1.nested2" : 2
}
jsonString - the string representation of the JSON object.delimiter - the delimiter to use when joining the keys.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static org.json.JSONObject flattenToJSONObject(String jsonString) throws org.json.JSONException
jsonString - the string representation of the JSON object.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static org.json.JSONObject flattenToJSONObject(org.json.JSONObject jsonObject)
throws org.json.JSONException
jsonObject - the JSON object to flatten.org.json.JSONExceptionpublic static org.json.JSONObject flattenToJSONObject(String jsonString, String delimiter) throws org.json.JSONException
jsonString - the string representation of the JSON object.delimiter - the delimiter to use when joining the keys.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static org.json.JSONObject flattenToJSONObject(org.json.JSONObject jsonObject,
String delimiter)
throws org.json.JSONException
jsonObject - the JSON object to flatten.delimiter - the delimiter to use when joining the keys.org.json.JSONExceptionpublic static String unflatten(String flatJsonString) throws org.json.JSONException
flatJsonString - the string representation of the JSON object.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static String unflatten(org.json.JSONObject flatJsonObject) throws org.json.JSONException
flatJsonObject - the JSON object to unflatten.org.json.JSONExceptionpublic static String unflatten(String flatJsonString, String delimiter) throws org.json.JSONException
flatJsonString - the JSON object to unflatten.delimiter - the delimiter to use when splitting the keys.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static String unflatten(org.json.JSONObject flatJsonObject, String delimiter) throws org.json.JSONException
flatJsonObject - the JSON object to unflatten.delimiter - the delimiter to use when splitting the keys.org.json.JSONExceptionpublic static org.json.JSONObject unflattenToJSONObject(String flatJsonObject) throws org.json.JSONException
flatJsonObject - the string representation of the JSON object.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static org.json.JSONObject unflattenToJSONObject(org.json.JSONObject flatJsonObject)
throws org.json.JSONException
flatJsonObject - the JSON object to unflatten.org.json.JSONExceptionpublic static org.json.JSONObject unflattenToJSONObject(String flatJsonString, String delimiter) throws org.json.JSONException
flatJsonString - the JSON object to unflatten.delimiter - the delimiter to use when splitting the keys.org.json.JSONException - when the given string cannot be parsed to a JSON object.public static org.json.JSONObject unflattenToJSONObject(org.json.JSONObject flatJsonObject,
String delimiter)
throws org.json.JSONException
flatJsonObject - the JSON object to unflatten.delimiter - the delimiter to use when splitting the keys.org.json.JSONExceptionCopyright © 2016. All rights reserved.