execute json xpath(key a, expression b, array as text c, ignore exception d)
Gruppe |
Führt eine XPath-ähnliche Abfrage b gegen ein im internen Cache vorhandenes JSON-Objekt (unter Schlüssel a) aus. Siehe Funktion parse json and add to cache(data a, key b).
Das Ergebnis ist entweder ein String oder eine Zahl (bei Listen und Maps ist das die Größe der Liste bzw. der Map, wenn Parameter c false ist).
Parameterbeschreibung
Parameter |
Beschreibung |
a |
Schlüsselname des JSON-Objekts im Cache. |
b |
Der Abfrage-Ausdruck. Siehe https://github.com/json-path/JsonPath. |
c |
true gibt statt der Größe des Arrays (Liste) den JSON-Text zurück, false die Anzahl. Gilt nicht für Maps. |
d |
Falls true, dann wird eine aufgetretene Exception ignoriert und ein leerer String zurückgegeben. Default: <leer> (== false). |
Beispiele
Datei:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
Parameter b: $.store.book[*].author
Parameter c: false
Ergebnis: 4 (vier mal author gefunden)
Parameter b: $.store.book[*].author
Parameter c: true
Ergebnis: ["Nigel Rees","Evelyn Waugh","Herman Melville","J. R. R. Tolkien"]
Datei:
{"date_as_long": 1411455611975}
Parameter b: $['date_as_long']
Parameter c: true oder false (keine Auswirkung, da kein Array/Liste)
Ergebnis: 1411455611975 (als String)