|
1 |
| -jsonq |
2 |
| -===== |
| 1 | +Querying JSON Terms |
| 2 | +------------------- |
| 3 | + |
| 4 | +JSON: |
| 5 | + |
| 6 | + {"store": { |
| 7 | + "books": [ |
| 8 | + { |
| 9 | + "category": "fiction", |
| 10 | + "author": "J. R. R. Tolkien", |
| 11 | + "title": "The Lord of the Rings", |
| 12 | + "isbn": "0-395-19395-8", |
| 13 | + "price": 22.99 |
| 14 | + }, |
| 15 | + { |
| 16 | + "category": "fiction", |
| 17 | + "author": ["Arkady N. Strugatsky", "Boris N. Strugatsky"], |
| 18 | + "title": "Monday Begins on Saturday", |
| 19 | + "isbn": "0-000-000000-0", |
| 20 | + "price": 22.99 |
| 21 | + } |
| 22 | + ], |
| 23 | + "bicycle": { |
| 24 | + "color": "red", |
| 25 | + "price": 19.95 |
| 26 | + } |
| 27 | + }} |
| 28 | + |
| 29 | +Erlang JSON term: |
| 30 | + |
| 31 | + Json = {[{<<"store">>, |
| 32 | + {[{<<"books">>, [ |
| 33 | + {[ |
| 34 | + {<<"category">>,<<"fiction">>}, |
| 35 | + {<<"author">>,<<"J. R. R. Tolkien">>}, |
| 36 | + {<<"title">>,<<"The Lord of the Rings">>}, |
| 37 | + {<<"isbn">>,<<"0-395-19395-8">>}, |
| 38 | + {<<"price">>,22.99} |
| 39 | + ]}, |
| 40 | + {[ |
| 41 | + {<<"category">>,<<"fiction">>}, |
| 42 | + {<<"author">>, [<<"Arkady N. Strugatsky">>,<<"Boris N. Strugatsky">>]}, |
| 43 | + {<<"title">>,<<"Monday Begins on Saturday">>}, |
| 44 | + {<<"isbn">>,<<"0-000-000000-0">>}, |
| 45 | + {<<"price">>,22.99} |
| 46 | + ]} |
| 47 | + ]}, |
| 48 | + {<<"bicycle">>, {[ |
| 49 | + {<<"color">>,<<"red">>}, |
| 50 | + {<<"price">>,19.95} |
| 51 | + ]} |
| 52 | + }]}}]}. |
| 53 | + |
| 54 | +Query example 1: |
| 55 | + |
| 56 | + jsonq:q([<<"store">>], Json). |
| 57 | + |
| 58 | + {[{<<"books">>, [ |
| 59 | + {[ |
| 60 | + {<<"category">>,<<"fiction">>}, |
| 61 | + {<<"author">>,<<"J. R. R. Tolkien">>}, |
| 62 | + {<<"title">>,<<"The Lord of the Rings">>}, |
| 63 | + {<<"isbn">>,<<"0-395-19395-8">>}, |
| 64 | + {<<"price">>,22.99} |
| 65 | + ]}, |
| 66 | + {[ |
| 67 | + {<<"category">>,<<"fiction">>}, |
| 68 | + {<<"author">>, [<<"Arkady N. Strugatsky">>,<<"Boris N. Strugatsky">>]}, |
| 69 | + {<<"title">>,<<"Monday Begins on Saturday">>}, |
| 70 | + {<<"isbn">>,<<"0-000-000000-0">>}, |
| 71 | + {<<"price">>,22.99} |
| 72 | + ]} |
| 73 | + ]} |
| 74 | + |
| 75 | +Query example 2: |
| 76 | + |
| 77 | + jsonq:q([<<"store">>, <<"books">>], Json). |
| 78 | + [ |
| 79 | + {[ |
| 80 | + {<<"category">>,<<"fiction">>}, |
| 81 | + {<<"author">>,<<"J. R. R. Tolkien">>}, |
| 82 | + {<<"title">>,<<"The Lord of the Rings">>}, |
| 83 | + {<<"isbn">>,<<"0-395-19395-8">>}, |
| 84 | + {<<"price">>,22.99} |
| 85 | + ]}, |
| 86 | + {[ |
| 87 | + {<<"category">>,<<"fiction">>}, |
| 88 | + {<<"author">>, [<<"Arkady N. Strugatsky">>,<<"Boris N. Strugatsky">>]}, |
| 89 | + {<<"title">>,<<"Monday Begins on Saturday">>}, |
| 90 | + {<<"isbn">>,<<"0-000-000000-0">>}, |
| 91 | + {<<"price">>,22.99} |
| 92 | + ]} |
| 93 | + ] |
| 94 | + |
| 95 | +Query example 3: |
| 96 | + |
| 97 | + jsonq:q([<<"store">>, <<"books">>, 0], Json). |
| 98 | + |
| 99 | + {[ |
| 100 | + {<<"category">>,<<"fiction">>}, |
| 101 | + {<<"author">>,<<"J. R. R. Tolkien">>}, |
| 102 | + {<<"title">>,<<"The Lord of the Rings">>}, |
| 103 | + {<<"isbn">>,<<"0-395-19395-8">>}, |
| 104 | + {<<"price">>,22.99} |
| 105 | + ]} |
| 106 | + |
| 107 | +Query example 4: |
| 108 | + |
| 109 | + jsonq:q([<<"store">>, <<"books">>, 1, <<"author">>, 1], Json). |
| 110 | + |
| 111 | + <<"Boris N. Strugatsky">> |
| 112 | + |
| 113 | +Query example 5: |
| 114 | + |
| 115 | + jsonq:q([<<"store">>, <<"toys">>], Json). |
| 116 | + |
| 117 | + undefined |
0 commit comments