Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
PPLJSONFunktionen
Anmerkung
Informationen darüber, welche AWS Datenquellenintegrationen diese PPL Funktion unterstützen, finden Sie unterFunktionen.
JSON
Verwendung: json(value)
Prüft, ob eine Zeichenfolge als Format analysiert werden kann. JSON Die Funktion gibt die ursprüngliche Zeichenfolge zurück, wenn sie gültig istJSON, oder Null, wenn sie ungültig ist.
Typ des Arguments: STRING
Rückgabetyp:STRING/NULL. Ein STRING Ausdruck eines gültigen JSON Objektformats.
Beispiele:
os> source=people | eval `valid_json()` = json('[1,2,3,{"f1":1,"f2":[5,6]},4]') | fields valid_json fetched rows / total rows = 1/1 +---------------------------------+ | valid_json | +---------------------------------+ | [1,2,3,{"f1":1,"f2":[5,6]},4] | +---------------------------------+ os> source=people | eval `invalid_json()` = json('{"invalid": "json"') | fields invalid_json fetched rows / total rows = 1/1 +----------------+ | invalid_json | +----------------+ | null | +----------------+
JSON_OBJECT
Verwendung: json_object(<key>, <value>[, <key>,
<value>]...)
Gibt ein JSON Objekt aus Mitgliedern von Schlüssel-Wert-Paaren zurück.
Typ des Arguments:
Ein <key>MussSTRING.
A <value>kann ein beliebiger Datentyp sein.
Rückgabetyp: JSON _OBJECT. Ein StructType Ausdruck eines gültigen JSON Objekts.
Beispiele:
os> source=people | eval result = json_object('key', 123.45) | fields result fetched rows / total rows = 1/1 +------------------+ | result | +------------------+ | {"key":123.45} | +------------------+ os> source=people | eval result = json_object('outer', json_object('inner', 123.45)) | fields result fetched rows / total rows = 1/1 +------------------------------+ | result | +------------------------------+ | {"outer":{"inner":123.45}} | +------------------------------+
JSON_ARRAY
Verwendung: json_array(<value>...)
erstellt eine JSON ARRAY unter Verwendung einer Werteliste.
Argumenttyp: A <value>
kann ein beliebiger Wert sein, z. B. eine Zeichenfolge, eine Zahl oder ein boolescher Wert.
Rückgabetyp:. ARRAY Ein Array mit einem beliebigen unterstützten Datentyp für ein gültiges JSON Array.
Beispiele:
os> source=people | eval `json_array` = json_array(1, 2, 0, -1, 1.1, -0.11) fetched rows / total rows = 1/1 +------------------------------+ | json_array | +------------------------------+ | [1.0,2.0,0.0,-1.0,1.1,-0.11] | +------------------------------+ os> source=people | eval `json_array_object` = json_object("array", json_array(1, 2, 0, -1, 1.1, -0.11)) fetched rows / total rows = 1/1 +----------------------------------------+ | json_array_object | +----------------------------------------+ | {"array":[1.0,2.0,0.0,-1.0,1.1,-0.11]} | +----------------------------------------+
TO_JSON_STRING
Verwendung: to_json_string(jsonObject)
Gibt eine JSON Zeichenfolge mit einem bestimmten JSON-Objektwert zurück.
Argumenttyp: JSON _ OBJECT
Rückgabetyp: STRING
Beispiele:
os> source=people | eval `json_string` = to_json_string(json_array(1, 2, 0, -1, 1.1, -0.11)) | fields json_string fetched rows / total rows = 1/1 +--------------------------------+ | json_string | +--------------------------------+ | [1.0,2.0,0.0,-1.0,1.1,-0.11] | +--------------------------------+ os> source=people | eval `json_string` = to_json_string(json_object('key', 123.45)) | fields json_string fetched rows / total rows = 1/1 +-----------------+ | json_string | +-----------------+ | {'key', 123.45} | +-----------------+
ARRAY_LENGTH
Verwendung: array_length(jsonArray)
Gibt die Anzahl der Elemente im äußersten Array zurück.
Argumenttyp:ARRAY. Ein ARRAY Objekt ARRAY oder JSON _.
Rückgabetyp: INTEGER
Beispiel:
os> source=people | eval `json_array` = json_array_length(json_array(1,2,3,4)), `empty_array` = json_array_length(json_array()) fetched rows / total rows = 1/1 +--------------+---------------+ | json_array | empty_array | +--------------+---------------+ | 4 | 0 | +--------------+---------------+
JSON_EXTRACT
Verwendung: json_extract(jsonStr,
path)
Extrahiert ein JSON Objekt aus einer JSON Zeichenfolge, die auf dem angegebenen JSON Pfad basiert. Die Funktion gibt Null zurück, wenn die JSON Eingabezeichenfolge ungültig ist.
Argumenttyp:STRING, STRING
Rückgabetyp: STRING
-
Ein STRING Ausdruck eines gültigen JSON Objektformats.
-
NULL
wird im Falle eines ungültigen zurückgegebenJSON.
Beispiele:
os> source=people | eval `json_extract('{"a":"b"}', '$.a')` = json_extract('{"a":"b"}', '$a') fetched rows / total rows = 1/1 +----------------------------------+ | json_extract('{"a":"b"}', 'a') | +----------------------------------+ | b | +----------------------------------+ os> source=people | eval `json_extract('{"a":[{"b":1},{"b":2}]}', '$.a[1].b')` = json_extract('{"a":[{"b":1},{"b":2}]}', '$.a[1].b') fetched rows / total rows = 1/1 +-----------------------------------------------------------+ | json_extract('{"a":[{"b":1.0},{"b":2.0}]}', '$.a[1].b') | +-----------------------------------------------------------+ | 2.0 | +-----------------------------------------------------------+ os> source=people | eval `json_extract('{"a":[{"b":1},{"b":2}]}', '$.a[*].b')` = json_extract('{"a":[{"b":1},{"b":2}]}', '$.a[*].b') fetched rows / total rows = 1/1 +-----------------------------------------------------------+ | json_extract('{"a":[{"b":1.0},{"b":2.0}]}', '$.a[*].b') | +-----------------------------------------------------------+ | [1.0,2.0] | +-----------------------------------------------------------+ os> source=people | eval `invalid_json` = json_extract('{"invalid": "json"') fetched rows / total rows = 1/1 +----------------+ | invalid_json | +----------------+ | null | +----------------+
JSON_KEYS
Verwendung: json_keys(jsonStr)
gibt alle Schlüssel des äußersten JSON Objekts als Array zurück.
Typ des Arguments:STRING. Ein STRING Ausdruck eines gültigen JSON Objektformats.
Rückgabetyp: ARRAY [STRING]. Die Funktion gibt NULL
für jede andere gültige JSON Zeichenfolge eine leere Zeichenfolge oder eine ungültige Zeichenfolge zurückJSON.
Beispiele:
os> source=people | eval `keys` = json_keys('{"f1":"abc","f2":{"f3":"a","f4":"b"}}') fetched rows / total rows = 1/1 +------------+ | keus | +------------+ | [f1, f2] | +------------+ os> source=people | eval `keys` = json_keys('[1,2,3,{"f1":1,"f2":[5,6]},4]') fetched rows / total rows = 1/1 +--------+ | keys | +--------+ | null | +--------+
JSON_VALID
Verwendung: json_valid(jsonStr)
Wertet aus, ob eine JSON Zeichenfolge eine gültige JSON Syntax verwendet, und gibt TRUE oder FALSE zurück.
Typ des Arguments: STRING
Rückgabetyp: BOOLEAN
Beispiele:
os> source=people | eval `valid_json` = json_valid('[1,2,3,4]'), `invalid_json` = json_valid('{"invalid": "json"') | feilds `valid_json`, `invalid_json` fetched rows / total rows = 1/1 +--------------+----------------+ | valid_json | invalid_json | +--------------+----------------+ | True | False | +--------------+----------------+ os> source=accounts | where json_valid('[1,2,3,4]') and isnull(email) | fields account_number, email fetched rows / total rows = 1/1 +------------------+---------+ | account_number | email | |------------------+---------| | 13 | null | +------------------+---------+