JSON-Funktionen im Jitterbit Design 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: Eine JSON-Objektzeichenfolge, aus der Daten extrahiert werden sollen.
- path: Ein gültiger Pfad, der den Standort der Daten in der JSON-Objektzeichenfolge darstellt.
Beschreibung
Extrahiert Daten aus einer JSON-Objektzeichenfolge mithilfe des angegebenen Pfades.
Wichtig
Diese Funktion erfordert die Design Studio-Version 11.28 oder höher und die Agent-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: Eine JSON-Objektzeichenfolge, die in ein JSON-Objekt umgewandelt werden soll.
Beschreibung
Konvertiert eine JSON-Objektzeichenfolge in ein JSON-Objekt.
Die maximale Größe der JSON-Objektzeichenfolge, die zu einem bestimmten Zeitpunkt an die Funktion JSONParser übergeben werden kann, hängt von der Hardware und der Arbeitslast des Agenten der Projektumgebung ab.
Wichtig
Diese Funktion erfordert die Design Studio-Version 11.29 oder höher und die Agent-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 umgewandelt werden soll.
Beschreibung
Wandelt ein JSON-Objekt in einen JSON-Objekt-String um.
Wichtig
Diese Funktion erfordert Design Studio Version 11.30 oder höher und Agent-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 Agent-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}]}]}'