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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
SELECT parse_json_path('..');
SELECT parse_json_path('..*');
SELECT parse_json_path('.*');
SELECT parse_json_path('');
SELECT parse_json_path('$.*');
SELECT parse_json_path('$');
SELECT parse_json_path('$*');
SELECT parse_json_path('*');
SELECT parse_json_path($$ .. [ 025 ] $$);
SELECT parse_json_path($$ $ . 0 . 3 $$);
SELECT parse_json_path($$ $ . 0_3 $$);
SELECT parse_json_path($$ $ . 0.3 $$);
SELECT parse_json_path($$ .. [ 031 ] $$);
SELECT parse_json_path($$ $ . 0 . 3 . hello $$);
SELECT parse_json_path($$ $ . 0 . 3 . hello . "back\\slash" $$);
SELECT parse_json_path($$ $ . 0 . 3 . hello . ["back\\slash"] $$);
SELECT parse_json_path($$ $ . 0 . 3 . hello . back\slash $$);
SELECT parse_json_path($$ $ . 0 . 3 . hello . backslash $$);
SELECT parse_json_path($$ .. [ 0x31 ] $$);
SELECT parse_json_path($$ [ 0x31 ] $$);
SELECT parse_json_path($$ _3 $$);
SELECT parse_json_path($$ _3_ $$);
SELECT parse_json_path($$ [ _3 ] $$);
SELECT parse_json_path($$ $ _3 $$);
SELECT parse_json_path($$ $ . _3 $$);
SELECT parse_json_path('..["5"]');
SELECT parse_json_path('..[5]');
SELECT parse_json_path('..5');
SELECT parse_json_path($$ .. [ -5 ] $$);
SELECT parse_json_path($$ .. [ "5" ] $$);
SELECT parse_json_path($$ .. [ +5 ] $$);
SELECT parse_json_path($$ .. [ 5 ] $$);
SELECT parse_json_path($$ .. ["5"] $$);
SELECT parse_json_path($$ ..["5"] $$);
SELECT parse_json_path($$ [ "5" ] $$);
SELECT parse_json_path($$ [ 5 ] $$);
SELECT parse_json_path('."hello"');
SELECT parse_json_path('.hello');
SELECT parse_json_path('...["hello world"]');
SELECT parse_json_path('..["hello world"]');
SELECT parse_json_path('."hello world"');
SELECT parse_json_path('.["hello world"]');
SELECT parse_json_path('.hello world');
SELECT parse_json_path('..["hello world"]["5"]');
SELECT parse_json_path('..["hello world"][5]');
SELECT parse_json_path('..["hello world"][5]..[3]..*.[*]');
SELECT parse_json_path('..["hello world"][5]..[3]..*');
SELECT parse_json_path('..["hello world"][5]..[3]');
SELECT parse_json_path('..["hello world"][5]..[3]*');
SELECT parse_json_path($$
.. [ '"hello"\\"world"' ]
[ 5 ] .. [3] . * [ * ]
$$);
select parse_json_path('$char');
select parse_json_path('$.char');
select parse_json_path('$.char()');
select parse_json_path('$.char(5)');
select parse_json_path('$.char( -1 )');
select parse_json_path('$.char( -1 ) . char(0)');
select parse_json_path('$.char( -1 ) . char ( 0 ) ');
select parse_json_path('$.char( +1 ) . char ( 0 ) ');
select parse_json_path('$ . char( +1 ) . char ( 0 ) ');
select parse_json_path('$ .. char( +1 ) . char ( 0 ) ');
select parse_json_path('$ .. char( +1 ) .. char ( 0 ) ');
select parse_json_path('$ . char( +1 ) .. char ( 0 ) ');
select parse_json_path('$ . char( +1 ) char ( 0 ) ');
select parse_json_path('$ char( +1 ) char ( 0 ) ');
select parse_json_path('char( +1 ) . char ( 0 ) ');
select parse_json_path('.char( +1 ) . char ( 0 ) ');
select parse_json_path('..char( +1 ) . char ( 0 ) ');
select parse_json_path('...char( +1 ) . char ( 0 ) ');
select parse_json_path('[char(5)]');
SELECT json_path($$"⁰¹\u0000³"$$, 'char(0)');
SELECT json_path($$"⁰¹\u0000³"$$, 'char(1)');
SELECT json_path($$"⁰¹\u0000³"$$, 'char(2)');
SELECT json_path($$"⁰¹\u0000³"$$, 'char(3)');
SELECT json_path('"0123"', 'char(-1)');
SELECT json_path('"0123"', 'char(0)');
SELECT json_path('"0123"', 'char(1)');
SELECT json_path('"0123"', 'char(2)');
SELECT json_path('"0123"', 'char(3)');
SELECT json_path('"0123"', 'char(4)');
SELECT json_path('"⁰¹²³"', 'char(0)');
SELECT json_path('"⁰¹²³"', 'char(1)');
SELECT json_path('"⁰¹²³"', 'char(2)');
SELECT json_path('"⁰¹²³"', 'char(3)');
SELECT json_path('[1,2,3]', '$');
SELECT json_path('[1,2,3]', '$.+1');
SELECT json_path('[1,2,3]', '$.-1');
SELECT json_path('[1,2,3]', '$.0');
SELECT json_path('[1,2,3]', '$.1');
SELECT json_path('[1,2,3]', '$.2');
SELECT json_path('[1,2,3]', '$.3');
SELECT json_path('[1,2,3]', '*');
SELECT json_path('[1,2,3]', '[0]');
SELECT json_path('[1,2,3]', '[1]');
SELECT json_path('[1,2,3]', '[2]');
SELECT json_path('{"0": "zero", "1": "one", "2": "two"}', $$['2']$$);
SELECT json_path('{"0": "zero", "1": "one", "2": "two"}', '["0"]');
SELECT json_path('{"0": "zero", "1": "one", "2": "two"}', '["1"]');
SELECT json_path('{"0": "zero", "1": "one", "2": "two"}', '["2"]');
SELECT json_path('{"0": "zero", "1": "one", "2": "two"}', '[0]');
SELECT json_path('{"0": "zero", "1": "one", "2": "two"}', '[1]');
-- Multiple JSONPath results are listed in BFS order
-- (just because it's easier to implement efficiently than DFS)
SELECT json_path('[0,1,[2, [3,4 , 5],6,[7,8],9],10]', '$..*');
CREATE TABLE sample (json JSON);
INSERT INTO sample VALUES ($$
{
"store": {
"books": [
{
"title": "book 0",
"author": "author 0",
"prices": [1,2,3]
}, {
"title": "book 1",
"author": "author 1",
"prices": [4,5,6]
}, {
"title": "book 2",
"author": "author 2",
"prices": [7,8,9]
}
],
"toys": [
"Yo-yo",
"Boomerang",
"Basketball"
]
}
}
$$);
-- Use unaligned output so results are consistent between PostgreSQL 8 and 9.
\a
SELECT json_path(json, 'store.books[*]') FROM sample;
SELECT json_path(json, 'store.books[*].title') FROM sample;
SELECT json_path(json, 'store.books[*].author') FROM sample;
SELECT json_path(json, 'store.books[*].prices') FROM sample;
SELECT json_path(json, 'store.books[*].prices[*]') FROM sample;
SELECT json_path(json, 'store.toys[*]') FROM sample;
SELECT json_path(json, 'store.toys[*][0]') FROM sample;
SELECT json_path(json, 'store.toys[*][1]') FROM sample;
SELECT json_path(json, 'store.toys[*][0][0]') FROM sample;
SELECT json_path(json, 'store.toys[*][0][1]') FROM sample;
SELECT json_path(json, '..books') FROM sample;
SELECT json_path(json, '..books[*]') FROM sample;
SELECT json_path(json, '..title') FROM sample;
SELECT json_path(json, '..author') FROM sample;
SELECT json_path(json, '..prices[*]') FROM sample;
SELECT json_path(json, '..toys[*]') FROM sample;
SELECT json_path(json, '..toys..[*]') FROM sample;
SELECT json_path(json, '..[-1]') FROM sample;
SELECT json_path(json, '..[0]') FROM sample;
SELECT json_path(json, '..[1]') FROM sample;
SELECT json_path(json, '..[2]') FROM sample;
SELECT json_path(json, '..[3]') FROM sample;
SELECT json_path(json, '$') FROM sample;
SELECT json_path(json, '..*') FROM sample;
SELECT json_path(json, '..char(-1)') FROM sample;
SELECT json_path(json, '..char(0)') FROM sample;
SELECT json_path(json, '..char(1)') FROM sample;
SELECT json_path(json, '..char(2)') FROM sample;
SELECT json_path(json, '..char(3)') FROM sample;
SELECT json_path(json, '..char(100)') FROM sample;
-- Turn aligned output back on.
\a
|