1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# This file is part of Grecs -*- Autotest -*-
# Copyright (C) 2015 Sergey Poznyakoff
#
# Grecs is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# Grecs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([Lookup])
AT_KEYWORDS([json json01 lookup])
AT_DATA([input.json],[[
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}
]])
m4_define([json_query],[
echo $1
json -indent=2 -precision=0 -file=input.json -search=$1
echo =$?
])
AT_CHECK([json_query(age)
json_query(address)
json_query(address.postalCode)
json_query(phoneNumbers.1.number)
json_query(x)
json_query(x.y.z)
json_query(phoneNumbers.2.number)
json_query(phoneNumbers.x)
],
[0],
[age
25
=0
address
{
"city": "New York",
"postalCode": "10021-3100",
"state": "NY",
"streetAddress": "21 2nd Street"
}
=0
address.postalCode
"10021-3100"
=0
phoneNumbers.1.number
"646 555-4567"
=0
x
=4
x.y.z
=4
phoneNumbers.2.number
=4
phoneNumbers.x
=4
])
AT_CLEANUP
|