public class JSONUtils extends Object
| Constructor and Description |
|---|
JSONUtils() |
| Modifier and Type | Method and Description |
|---|---|
static BJSON |
convertArrayToJSON(BBooleanArray booleanArray)
Convert
BBooleanArray to BJSON. |
static BJSON |
convertArrayToJSON(BFloatArray floatArray)
Convert
BFloatArray to BJSON. |
static BJSON |
convertArrayToJSON(BIntArray intArray)
|
static BJSON |
convertArrayToJSON(BNewArray bArray)
|
static BJSON |
convertArrayToJSON(BRefValueArray refValueArray)
Convert
BRefValueArray to BJSON. |
static BJSON |
convertArrayToJSON(BStringArray stringArray)
Convert
BStringArray to BJSON. |
static BStruct |
convertJSONNodeToStruct(JsonNode jsonNode,
BStructType structType)
Convert a BJSON to a user defined struct.
|
static BStruct |
convertJSONToStruct(BJSON bjson,
BStructType structType)
Convert a BJSON to a user defined struct.
|
static BJSON |
convertMapToJSON(BMap<String,BValue> map)
|
static BJSON |
convertStructToJSON(BStruct struct)
|
static BJSON |
convertStructToJSON(BStruct struct,
BJSONType targetType)
|
static BXML |
convertToXML(BJSON json,
String attributePrefix,
String arrayEntryTag)
Converts given json object to the corresponding xml.
|
static BRefType<?> |
convertUnionTypeToJSON(BRefType<?> source) |
static BJSON |
getArrayElement(BJSON json,
long index)
Get an element from a JSON array.
|
static BJSON |
getElement(BJSON json,
String elementName)
Get an element from a JSON.
|
static int |
getJSONArrayLength(BJSON json)
Returns the size of JSON Array.
|
static BStringArray |
getKeys(BJSON json)
Returns the keys of a JSON as a
BStringArray. |
static String |
getTypeName(JsonNode jsonValue) |
static boolean |
hasElement(BJSON json,
String elementName)
Check whether JSON has particular field.
|
static boolean |
isJSONArray(BJSON json)
Check whether provided JSON object is a JSON Array.
|
static void |
remove(BJSON json,
String fieldName)
Remove a field from JSON.
|
static void |
setArrayElement(BJSON json,
long index,
BJSON element)
Set an element in the given position of a JSON array.
|
static void |
setElement(BJSON json,
String elementName,
BJSON element)
Set an element in a JSON.
|
static BJSON |
toJSON(BTable table,
boolean isInTransaction)
|
public static boolean hasElement(BJSON json, String elementName)
json - JSON to be considered.elementName - String name json field to be considered.public static BJSON convertArrayToJSON(BFloatArray floatArray)
BFloatArray to BJSON.floatArray - BFloatArray to be converted to BJSONpublic static BJSON convertArrayToJSON(BStringArray stringArray)
BStringArray to BJSON.stringArray - BStringArray to be converted to BJSONpublic static BJSON convertArrayToJSON(BBooleanArray booleanArray)
BBooleanArray to BJSON.booleanArray - BBooleanArray to be converted to BJSONpublic static BJSON convertArrayToJSON(BRefValueArray refValueArray)
BRefValueArray to BJSON.refValueArray - BRefValueArray to be converted to BJSONpublic static BJSON getElement(BJSON json, String elementName)
json - JSON object to get the element fromelementName - Name of the element to be retrievedpublic static void setElement(BJSON json, String elementName, BJSON element)
json - JSON object to set the elementelementName - Name of the element to be setelement - JSON elementpublic static boolean isJSONArray(BJSON json)
json - JSON to execute array condition.public static int getJSONArrayLength(BJSON json)
json - JSON to calculate array size.public static BJSON getArrayElement(BJSON json, long index)
json - JSON array to get the element fromindex - Index of the element neededpublic static void setArrayElement(BJSON json, long index, BJSON element)
json - JSON array to set the elementindex - Index of the element to be setelement - Element to be setpublic static BXML convertToXML(BJSON json, String attributePrefix, String arrayEntryTag)
json - JSON object to get the corresponding xmlattributePrefix - String prefix used for attributesarrayEntryTag - String used as the tag in the arrayspublic static BStruct convertJSONToStruct(BJSON bjson, BStructType structType)
bjson - JSON to convertstructType - Type (definition) of the target structBStruct containing the values
of the JSON object. Otherwise the method will throw a BallerinaException.public static BStruct convertJSONNodeToStruct(JsonNode jsonNode, BStructType structType)
jsonNode - JSON to convertstructType - Type (definition) of the target structBStruct containing the values
of the JSON object. Otherwise the method will throw a BallerinaException.public static BStringArray getKeys(BJSON json)
BStringArray.json - BJSON to get the keysBStringArraypublic static void remove(BJSON json, String fieldName)
json - JSON objectfieldName - Name of the field to removeCopyright © 2018 WSO2. All rights reserved.