Funções JSON no Jitterbit Integration Studio
Introdução
JavaScript Object Notation (JSON) permite a manipulação de dados no formato JSON. Para mais informações sobre JSON, consulte IETF RFC 8259: O 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 da qual extrair dados.
- path: Um caminho válido representando a localização dos dados na string de objeto JSON.
Descrição
Recupera dados de uma string de objeto JSON usando o caminho fornecido.
Importante
Esta função requer a versão do agente 11.28 ou posterior.
Exemplos
// 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
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.
O tamanho máximo da string de objeto JSON que pode ser passada para a função JSONParser em um dado momento depende do hardware do agente e da carga de trabalho do ambiente do projeto.
Importante
Esta função requer a versão do agente 11.29 ou posterior.
Exemplos
// 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
Declaração
string JSONStringify(dictionary json_object)
Sintaxe
JSONStringify(<json_object>)
Parâmetros obrigatórios
- json_object: Um objeto JSON a ser convertido em uma string de objeto JSON.
Descrição
Converte um objeto JSON em uma string de objeto JSON.
Importante
Esta função requer a versão do agente 11.30 ou posterior. O suporte para caracteres JSON reservados, como " e \, e a capacidade de lidar com dados nulos requer a versão do agente 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}]}]}'