Ir para o conteúdo

Funções JSON no Jitterbit Integration Studio

Introdução

Notação de Objeto JavaScript As funções (JSON) permitem a manipulação de dados no formato JSON. Para obter mais informações sobre JSON, consulte IETF RFC 8259: Formato de Intercâmbio de Dados JavaScript Object Notation (JSON).

GetJSONString

Declaração

string GetJSONString(string json_string, string path)

Sintaxe

GetJSONString(<json_string>, <path>)

Parâmetros obrigatórios

  • json_string: Uma string de objeto JSON para analisar dados.
  • path: Um caminho que representa a localização dos dados na string do objeto JSON.

Descrição

Recupera dados de uma string de objeto JSON usando o caminho fornecido.

Importante

Esta função requer a versão 11.28 ou posterior do agente.

Exemplos

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

Declaração

dictionary JSONParser(string json_string)

Sintaxe

JSONParser(<json_string>)

Parâmetros obrigatórios

  • json_string: Uma string de objeto JSON a ser convertida em um objeto JSON.

Descrição

Converte uma string de objeto JSON em um objeto JSON.

Importante

Esta função requer a versão 11.29 ou posterior do agente.

Exemplos

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

Declaração

string JSONStringify(dictionary json_object)

Sintaxe

JSONStringify(<json_object>)

Parâmetros obrigatórios

  • json_object: Um objeto JSON para converter em uma string de objeto JSON.

Descrição

Converte um objeto JSON em uma string de objeto JSON.

Importante

Esta função requer o agente versão 11.30 ou posterior. Suporte para caracteres JSON reservados, como " e \ e ser capaz de manipular dados nulos requer o agente versão 11.45 ou posterior.

Exemplo

// 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}]}]}'