Skip to Content

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": "Jitterbit iPaaS" },{ "type": "EDI", "name": "Jitterbit EDI" }] }] }';

GetJSONString(json_string, "/company/[0]/product/[1]/name");
// Returns "Jitterbit EDI"

GetJSONString(json_string, "/company/[0]/product");
// Returns '[{"type":"iPaaS","name":"Jitterbit iPaaS"},{"type":"EDI","name":"Jitterbit 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": "Jitterbit iPaaS" },{ "type": "EDI", "name": "Jitterbit EDI" }] }] }';

// Convert the JSON object string into a JSON object:
json_object = JSONParser(json_string);

result = json_object["company"][0]["product"][1]["name"];
// Equals "Jitterbit EDI"

result = json_object["company"][0]["product"];
// Equals {"[name=>""Jitterbit iPaaS"",type=>""iPaaS""]","[name=>""Jitterbit EDI"",type=>""EDI""]"}

JSONStringify

Declaration

string JSONStringify(dictionary json_object)

Syntax

JSONStringify(<json_object>)

Required parameters

  • json_object: A JSON object to convert into a JSON object string.

Description

Converts a JSON object into a JSON object string.

Important

This function requires agent version 11.30 or later.

Example

// Define the JSON object structure:
json_object = Dict();
json_object["company"][0] = Dict();
json_object["company"][0]["name"] = "Jitterbit";
json_object["company"][0]["product"][0] = Dict();
json_object["company"][0]["product"][0]["type"] = "iPaaS";
json_object["company"][0]["product"][0]["name"] = "Jitterbit iPaaS";
json_object["company"][0]["product"][1] = Dict();
json_object["company"][0]["product"][1]["type"] = "EDI";
json_object["company"][0]["product"][1]["name"] = "Jitterbit EDI";

JSONStringify(json_object);
// Returns '{"company":[{"name":"Jitterbit", "product":[{"name":"Jitterbit iPaaS", "type":"iPaaS"}, {"name":"Jitterbit EDI", "type":"EDI"}]}]}'