Functions of ballerina.lang.jsons package
function addToArray(json j, string jsonPath, any value)
Inserts a Boolean to a JSON array. This function will add a new Boolean element to the end of the JSON array identified by the given JSONPath.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON array object |
jsonPath | string | The path of the JSON element |
value | any | A any value |
function addToObject(json j, string jsonPath, string key, any value)
Inserts a named element to a JSON object. This method will add a new JSON element with the given name (key)
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
key | string | The name of the element to be added |
value | any | A any value |
function getBoolean(json j, string jsonPath) (boolean )
Evaluates the JSONPath on a JSON object and returns the Boolean value.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | The Boolean element on the specified path |
function getFloat(json j, string jsonPath) (float )
Evaluates the JSONPath on a JSON object and returns the integer value.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
float | The float element on the specified path |
function getInt(json j, string jsonPath) (int )
Evaluates the JSONPath on a JSON object and returns the integer value.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A json object |
jsonPath | string | The path of the JSON element |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | The integer element on the specified path |
function getJson(json j, string jsonPath) (json )
Evaluates the JSONPath on a JSON object and returns the matching JSON.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
json | The JSON element on the specified path |
function getKeys(json j) (string[] )
Returns an array of keys contained in the specified JSON.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string[] | string[]: A string array of keys contained in the specified JSON |
function getString(json j, string jsonPath) (string )
Evaluates the JSONPath on a JSON object and returns the string value
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | The string element on the specified path |
function parse(string jsonStr) (json )
Parses the string argument as a JSON value.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
jsonStr | string | String representation of JSON |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
json | Parsed JSON value |
function remove(json j, string jsonPath)
Removes each element that matches the given JSONPath.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
function rename(json j, string jsonPath, string oldKey, string newKey)
Renames the key of the given element that is under the given JSONPath.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
oldKey | string | The old key value |
newKey | string | The new key value to use |
function set(json j, string jsonPath, any value)
Sets the integer value of the element that matches the given JSONPath. If the JSONPath doesn't match any element, this operation will have no effect.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
jsonPath | string | The path of the JSON element |
value | any | An any value |
function toString(json j) (string )
Converts a JSON object to a string representation
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | String value of the converted JSON |
function toXML(json j, Options options) (xml )
Converts a JSON object to a XML representation
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
j | json | A JSON object |
options | Options | j: A JSON object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml | XML value of the converted JSON |
Structs of ballerina.lang.jsons package
struct Options
Fields:
Field Name | Data Type | Description |
---|---|---|
attributePrefix | string | |
arrayEntryTag | string |