JSON-Funktionen im Jitterbit Integration Studio
Einführung
JavaScript Object Notation (JSON) Funktionen ermöglichen die Manipulation von Daten im JSON-Format. Für weitere Informationen zu JSON siehe IETF RFC 8259: Das JavaScript Object Notation (JSON) Datenformat.
GetJSONString
Deklaration
string GetJSONString(string json_string, string path)
Syntax
GetJSONString(<json_string>, <path>)
Erforderliche Parameter
json_string: Ein JSON-Objekt-String, aus dem Daten geparst werden sollen.path: Ein gültiger Pfad, der den Standort der Daten im JSON-Objekt-String darstellt.
Beschreibung
Ruft Daten aus einem JSON-Objekt-String unter Verwendung des angegebenen Pfades ab.
Wichtig
Diese Funktion erfordert die Agenten-Version 11.28 oder höher.
Beispiele
// 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
Deklaration
dictionary JSONParser(string json_string)
Syntax
JSONParser(<json_string>)
Erforderliche Parameter
json_string: Ein JSON-Objekt-String, der in ein JSON-Objekt umgewandelt werden soll.
Beschreibung
Konvertiert einen JSON-Objekt-String in ein JSON-Objekt.
Die maximale Größe des JSON-Objekt-Strings, der zur Funktion JSONParser zu einem bestimmten Zeitpunkt übergeben werden kann, hängt von der Hardware und der Arbeitslast des Agenten der Projektumgebung ab.
Wichtig
Diese Funktion erfordert die Agenten-Version 11.29 oder höher.
Beispiele
// 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
Deklaration
string JSONStringify(dictionary json_object)
Syntax
JSONStringify(<json_object>)
Erforderliche Parameter
json_object: Ein JSON-Objekt, das in einen JSON-Objekt-String konvertiert werden soll.
Beschreibung
Konvertiert ein JSON-Objekt in einen JSON-Objekt-String.
Wichtig
Diese Funktion erfordert die Agenten-Version 11.30 oder höher. Die Unterstützung für reservierte JSON-Zeichen wie " und \ sowie die Fähigkeit, null-Daten zu verarbeiten, erfordert die Agenten-Version 11.45 oder höher.
Beispiel
// 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}]}]}'