JSON functions¶
Introduction¶
JavaScript Object Notation (JSON) functions allow for the manipulation of data in the JSON format. For more information on JSON, refer to IETF RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format.
GetJSONString
¶
Declaration¶
string GetJSONString(string json_string, string path)
Syntax¶
GetJSONString(<json_string>, <path>)
Required parameters¶
json_string
: A JSON object string to parse data from.path
: A path representing the location of the data in the JSON object string.
Description¶
Retrieves data from a JSON object string using the provided path.
Important
This function requires agent version 11.28 or later.
Examples¶
// Define the JSON object string:
json_string = '{ "company": [{ "name": "Jitterbit", "product": [{ "type": "iPaaS", "name": "Harmony iPaaS" },{ "type": "EDI", "name": "Harmony EDI" }] }] }';
GetJSONString(json_string, "/company/[0]/product/[1]/name");
// Returns "Harmony EDI"
GetJSONString(json_string, "/company/[0]/product");
// Returns '[{"type":"iPaaS","name":"Harmony iPaaS"},{"type":"EDI","name":"Harmony EDI"}]'
JSONParser
¶
Declaration¶
dictionary JSONParser(string json_string)
Syntax¶
JSONParser(<json_string>)
Required parameters¶
json_string
: A JSON object string to convert into a JSON object.
Description¶
Converts a JSON object string into a JSON object.
Important
This function requires agent version 11.29 or later.
Examples¶
// Define the JSON object string:
json_string = '{ "company": [{ "name": "Jitterbit", "product": [{ "type": "iPaaS", "name": "Harmony iPaaS" },{ "type": "EDI", "name": "Harmony EDI" }] }] }';
// Convert the JSON object string into a JSON object:
json_object = JSONParser(json_string);
result = json_object["company"][0]["product"][1]["name"];
// Equals "Harmony EDI"
result = json_object["company"][0]["product"];
// Equals {"[name=>""Harmony iPaaS"",type=>""iPaaS""]","[name=>""Harmony EDI"",type=>""EDI""]"}