« JSON » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
(→Liens) |
|||
Ligne 34 : | Ligne 34 : | ||
[http://www.jsonquerytool.com Online JSON query tester] | [http://www.jsonquerytool.com Online JSON query tester] | ||
* [https://www.npmjs.com/package/jsonpath-plus JSONPath Plus] | * [https://www.npmjs.com/package/jsonpath-plus JSONPath Plus] | ||
* XPath for JSON | * XPath for JSON | ||
* JSONPointer | * JSONPointer | ||
== [https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html JSONPath syntax] == | |||
<kode lang='json'> | |||
{ | |||
"A": "1", | |||
"B": { | |||
"X": "2" | |||
}, | |||
"C": { | |||
"X": "3" | |||
}, | |||
"D": [ | |||
{ | |||
"Y": "4", | |||
"Z": "44" | |||
}, | |||
{ | |||
"Y": "5", | |||
"Z": "55" | |||
} | |||
] | |||
} | |||
</kode> | |||
<kode lang='js'> | |||
A | |||
// [ "1" ] | |||
B.X | |||
// [ "2" ] | |||
*.X | |||
$..X | |||
// [ "2", "3" ] | |||
D[0] | |||
// { "Y": "4", "Z": "44" } | |||
D[*].Y | |||
// [ "4", "5" ] | |||
D[?(@.Y === "4")].Z | |||
// [ "44" ] | |||
</kode> |
Version du 28 janvier 2021 à 19:06
Liens
Définition
JavaScript Object Notation, tout comme XML, sert à sérialiser des données.
Structure
{ "nom": "valeur", "nom2": { "label1": "valeur", "label2": "valeur" }, "tableau": [ { "nom1": "valeur", "nom2": "valeur" }, { "nom1": "valeur", "nom2": "valeur" } ] } |
Query languages
- JSONPath Plus
- XPath for JSON
- JSONPointer
JSONPath syntax
{ "A": "1", "B": { "X": "2" }, "C": { "X": "3" }, "D": [ { "Y": "4", "Z": "44" }, { "Y": "5", "Z": "55" } ] } |
A // [ "1" ] B.X // [ "2" ] *.X $..X // [ "2", "3" ] D[0] // { "Y": "4", "Z": "44" } D[*].Y // [ "4", "5" ] D[?(@.Y === "4")].Z // [ "44" ] |