Saltar al contenido

Funciones JSON en Jitterbit Design Studio

Introducción

Notación de objetos de JavaScript las funciones JSON permiten la manipulación de datos en formato JSON. Para más información sobre JSON, consulte IETF RFC 8259: Formato de intercambio de datos de notación de objetos JavaScript (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 desde la que se analizarán los datos.
  • path: Una ruta que representa la ubicación de los datos en la cadena del objeto JSON.

Descripción

Recupera datos de una cadena de objeto JSON utilizando la ruta proporcionada.

Importante

Esta función requiere Design Studio versión 11.28 o posterior y agente versión 11.28 o posterior.

Ejemplos

// Define the JSON object string:
json_string = '{ "company":`[{ "nombre": "Jitterbit", "producto": [{ "tipo": "iPaaS", "nombre": "Jitterbit iPaaS" },{ "tipo": "EDI", "nombre": "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

Declaración

dictionary JSONParser(string json_string)

Sintaxis

JSONParser(<json_string>)

Parámetros requeridos

  • json_stringUna cadena de objeto JSON para convertirla en un objeto JSON.

Descripción

Convierte una cadena de objeto JSON en un objeto JSON.

Importante

Esta función requiere Design Studio versión 11.29 o posterior y agente versión 11.29 o posterior.

Ejemplos

// Define the JSON object string:
json_string = '{ "company":`[{ "nombre": "Jitterbit", "producto": [{ "tipo": "iPaaS", "nombre": "Jitterbit iPaaS" },{ "tipo": "EDI", "nombre": "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 para convertir en una cadena de objetos JSON.

Descripción

Convierte un objeto JSON en una cadena de objetos JSON.

Importante

Esta función requiere Design Studio versión 11.30 o posterior y la versión 11.30 o posterior del agente. Compatibilidad con caracteres JSON reservados como " y \ Para poder gestionar datos nulos se requiere 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}]}]}'