Funciones JSON en Jitterbit Integration Studio
Introducción
JavaScript Object Notation (JSON) permite la manipulación de datos en formato JSON. Para más información sobre JSON, consulte IETF RFC 8259: El formato de intercambio de datos JavaScript Object Notation (JSON).
GetJSONString
Declaración
string GetJSONString(string json_string, string path)
Sintaxis
GetJSONString(<json_string>, <path>)
Parámetros requeridos
- json_string: Una cadena de objeto JSON de la cual se extraerán los datos.
- path: Una ruta válida que representa la ubicación de los datos en la cadena de objeto JSON.
Descripción
Recupera datos de una cadena de objeto JSON utilizando la ruta proporcionada.
Importante
Esta función requiere la versión del agente 11.28 o posterior.
Ejemplos
// 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"}]'
GetJSONString(json_string, "/company/[0]/employees");
// Returns an "employees is not a valid path" error because companies do not have employees defined in the JSON object string
GetJSONString(json_string, "/company/[1]");
// Returns a "1 is out of range" error because only one company is defined in the JSON object string
JSONParser
Declaración
dictionary JSONParser(string json_string)
Sintaxis
JSONParser(<json_string>)
Parámetros requeridos
- json_string: Una cadena de objeto JSON que se convertirá en un objeto JSON.
Descripción
Convierte una cadena de objeto JSON en un objeto JSON.
El tamaño máximo de la cadena de objeto JSON que se puede pasar a la función JSONParser en un momento dado depende del hardware del agente del entorno del proyecto y de la carga de trabajo.
Importante
Esta función requiere la versión del agente 11.29 o posterior.
Ejemplos
// 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
Declaración
string JSONStringify(dictionary json_object)
Sintaxis
JSONStringify(<json_object>)
Parámetros requeridos
- json_object: Un objeto JSON que se convertirá en una cadena de objeto JSON.
Descripción
Convierte un objeto JSON en una cadena de objeto JSON.
Importante
Esta función requiere la versión 11.30 o posterior del agente. El soporte para caracteres JSON reservados como " y \ y la capacidad de manejar datos nulos requieren la versión 11.45 o posterior del agente.
Ejemplo
// 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"][0]["active"] = True;
json_object["company"][0]["product"][0]["internalID"] = 123;
json_object["company"][0]["product"][0]["description"] = 'Low-code integration solutions that deliver enterprise-grade performance.\nSecure, scalable, and AI-infused, Jitterbit iPaaS grows with your organization.\n"Request a free trial today!"';
json_object["company"][0]["product"][1] = Dict();
json_object["company"][0]["product"][1]["type"] = "EDI";
json_object["company"][0]["product"][1]["name"] = "Jitterbit EDI";
json_object["company"][0]["product"][1]["active"] = True;
json_object["company"][0]["product"][1]["internalID"] = 124;
json_object["company"][0]["product"][1]["description"] = null();
JSONStringify(json_object);
// Returns '{"company":[{"name":"Jitterbit", "product":[{"name":"Jitterbit iPaaS", "type":"iPaaS", "active":1, "internalID":123, "description":"Low-code integration solutions that deliver enterprise-grade performance.\\nSecure, scalable, and AI-infused, Jitterbit iPaaS grows with your organization.\\n\\"Request a free trial today!\\""},
            {"name":"Jitterbit EDI", "type":"EDI", "active":1, "internalID":124, "description":null}]}]}'