Imported Upstream version 1.2.4
[platform/upstream/json-glib.git] / doc / reference / html / JsonPath.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>JsonPath: JSON-GLib Reference Manual</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="index.html" title="JSON-GLib Reference Manual">
8 <link rel="up" href="ch02.html" title="Parser">
9 <link rel="prev" href="JsonReader.html" title="JsonReader">
10 <link rel="next" href="ch03.html" title="Generator">
11 <meta name="generator" content="GTK-Doc V1.25.1 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
16 <td width="100%" align="left" class="shortcuts">
17 <a href="#" class="shortcut">Top</a><span id="nav_description">  <span class="dim">|</span> 
18                   <a href="#JsonPath.description" class="shortcut">Description</a></span><span id="nav_hierarchy">  <span class="dim">|</span> 
19                   <a href="#JsonPath.object-hierarchy" class="shortcut">Object Hierarchy</a></span>
20 </td>
21 <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
22 <td><a accesskey="u" href="ch02.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
23 <td><a accesskey="p" href="JsonReader.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
24 <td><a accesskey="n" href="ch03.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
25 </tr></table>
26 <div class="refentry">
27 <a name="JsonPath"></a><div class="titlepage"></div>
28 <div class="refnamediv"><table width="100%"><tr>
29 <td valign="top">
30 <h2><span class="refentrytitle"><a name="JsonPath.top_of_page"></a>JsonPath</span></h2>
31 <p>JsonPath — JSONPath implementation</p>
32 </td>
33 <td class="gallery_image" valign="top" align="right"></td>
34 </tr></table></div>
35 <div class="refsect1">
36 <a name="JsonPath.functions"></a><h2>Functions</h2>
37 <div class="informaltable"><table class="informaltable" width="100%" border="0">
38 <colgroup>
39 <col width="150px" class="functions_return">
40 <col class="functions_name">
41 </colgroup>
42 <tbody>
43 <tr>
44 <td class="function_type">
45 <a class="link" href="JsonPath.html" title="JsonPath"><span class="returnvalue">JsonPath</span></a> *
46 </td>
47 <td class="function_name">
48 <a class="link" href="JsonPath.html#json-path-new" title="json_path_new ()">json_path_new</a> <span class="c_punctuation">()</span>
49 </td>
50 </tr>
51 <tr>
52 <td class="function_type">
53 <span class="returnvalue">gboolean</span>
54 </td>
55 <td class="function_name">
56 <a class="link" href="JsonPath.html#json-path-compile" title="json_path_compile ()">json_path_compile</a> <span class="c_punctuation">()</span>
57 </td>
58 </tr>
59 <tr>
60 <td class="function_type">
61 <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="returnvalue">JsonNode</span></a> *
62 </td>
63 <td class="function_name">
64 <a class="link" href="JsonPath.html#json-path-match" title="json_path_match ()">json_path_match</a> <span class="c_punctuation">()</span>
65 </td>
66 </tr>
67 <tr>
68 <td class="function_type">
69 <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="returnvalue">JsonNode</span></a> *
70 </td>
71 <td class="function_name">
72 <a class="link" href="JsonPath.html#json-path-query" title="json_path_query ()">json_path_query</a> <span class="c_punctuation">()</span>
73 </td>
74 </tr>
75 </tbody>
76 </table></div>
77 </div>
78 <div class="refsect1">
79 <a name="JsonPath.other"></a><h2>Types and Values</h2>
80 <div class="informaltable"><table class="informaltable" width="100%" border="0">
81 <colgroup>
82 <col width="150px" class="name">
83 <col class="description">
84 </colgroup>
85 <tbody>
86 <tr>
87 <td class="datatype_keyword"> </td>
88 <td class="function_name"><a class="link" href="JsonPath.html#JsonPath-struct" title="JsonPath">JsonPath</a></td>
89 </tr>
90 <tr>
91 <td class="datatype_keyword"> </td>
92 <td class="function_name"><a class="link" href="JsonPath.html#JsonPathClass" title="JsonPathClass">JsonPathClass</a></td>
93 </tr>
94 <tr>
95 <td class="define_keyword">#define</td>
96 <td class="function_name"><a class="link" href="JsonPath.html#JSON-PATH-ERROR:CAPS" title="JSON_PATH_ERROR">JSON_PATH_ERROR</a></td>
97 </tr>
98 <tr>
99 <td class="datatype_keyword">enum</td>
100 <td class="function_name"><a class="link" href="JsonPath.html#JsonPathError" title="enum JsonPathError">JsonPathError</a></td>
101 </tr>
102 </tbody>
103 </table></div>
104 </div>
105 <div class="refsect1">
106 <a name="JsonPath.object-hierarchy"></a><h2>Object Hierarchy</h2>
107 <pre class="screen">    GObject
108     <span class="lineart">╰──</span> JsonPath
109 </pre>
110 </div>
111 <div class="refsect1">
112 <a name="JsonPath.description"></a><h2>Description</h2>
113 <p><a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> is a simple class implementing the JSONPath syntax for extracting
114 data out of a JSON tree. While the semantics of the JSONPath expressions are
115 heavily borrowed by the XPath specification for XML, the syntax follows the
116 ECMAScript origins of JSON.</p>
117 <p>Once a <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> instance has been created, it has to compile a JSONPath
118 expression using <a class="link" href="JsonPath.html#json-path-compile" title="json_path_compile ()"><code class="function">json_path_compile()</code></a> before being able to match it to a
119 JSON tree; the same <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> instance can be used to match multiple JSON
120 trees. It it also possible to compile a new JSONPath expression using the
121 same <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> instance; the previous expression will be discarded only if
122 the compilation of the new expression is successful.</p>
123 <p>The simple convenience function <a class="link" href="JsonPath.html#json-path-query" title="json_path_query ()"><code class="function">json_path_query()</code></a> can be used for one-off
124 matching.</p>
125 <div class="refsect3">
126 <a name="id-1.4.3.4.6.5"></a><h4>Syntax of the JSONPath expressions</h4>
127 <p>A JSONPath expression is composed by path indices and operators.
128 Each path index can either be a member name or an element index inside
129 a JSON tree. A JSONPath expression must start with the '$' operator; each
130 path index is separated using either the dot notation or the bracket
131 notation, e.g.:</p>
132 <div class="informalexample">
133   <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
134     <tbody>
135       <tr>
136         <td class="listing_lines" align="right"><pre>1
137 2
138 3
139 4
140 5</pre></td>
141         <td class="listing_code"><pre class="programlisting"><span class="comment">// dot notation</span>
142 <span class="normal">$</span><span class="symbol">.</span><span class="normal">store</span><span class="symbol">.</span><span class="normal">book</span><span class="symbol">[</span><span class="number">0</span><span class="symbol">].</span><span class="normal">title</span>
143
144 <span class="comment">// bracket notation</span>
145 <span class="normal">$</span><span class="symbol">[</span><span class="string">'store'</span><span class="symbol">][</span><span class="string">'book'</span><span class="symbol">][</span><span class="number">0</span><span class="symbol">][</span><span class="string">'title'</span><span class="symbol">]</span></pre></td>
146       </tr>
147     </tbody>
148   </table>
149 </div>
150
151 <p></p>
152 <p>The available operators are:</p>
153 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
154 <li class="listitem"><p>Root node
155 The '$' character represents the root node of the JSON tree, and
156 matches the entire document.</p></li>
157 <li class="listitem"><p>Child nodes can either be matched using '.' or '[]'. For instance,
158 both <code class="literal">$.store.book</code> and `$'store' match the contents of
159 the book member of the store object.</p></li>
160 <li class="listitem"><p>Child nodes can be reached without specifying the whole tree structure
161 through the recursive descent operator, or '..'. For instance,
162 <code class="literal">$..author</code> matches all author member in every object.</p></li>
163 <li class="listitem"><p>Child nodes can grouped through the wildcard operator, or '*'. For
164 instance, <code class="literal">$.store.book[*].author</code> matches all author members of any
165 object element contained in the book array of the store object.</p></li>
166 <li class="listitem"><p>Element nodes can be accessed using their index (starting from zero)
167 in the subscript operator '[]'. For instance, <code class="literal">$.store.book[0]</code> matches
168 the first element of the book array of the store object.</p></li>
169 <li class="listitem"><p>Subsets of element nodes can be accessed using the set notation
170 operator '[start,end]'. For instance, <code class="literal">$.store.book[0,2]</code> matches the
171 first, second, and third elements of the book array of the store
172 object.</p></li>
173 <li class="listitem"><p>Slices of element nodes can be accessed using the slice notation
174 operation '[start:end:step]'. If start is omitted, the starting index
175 of the slice is implied to be zero; if end is omitted, the ending index
176 of the slice is implied to be the length of the array; if step is
177 omitted, the step of the slice is implied to be 1. For instance,
178 <code class="literal">$.store.book[:2]</code> matches the first two elements of the book array
179 of the store object.</p></li>
180 </ul></div>
181 <p>More information about JSONPath is available on Stefan Gössner's
182 <a class="ulink" href="http://goessner.net/articles/JsonPath/" target="_top">JSONPath website</a>.</p>
183 </div>
184 <div class="refsect3">
185 <a name="id-1.4.3.4.6.6"></a><h4>Example of JSONPath matches</h4>
186 <p>The following example shows some of the results of using <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a>
187 on a JSON tree. We use the following JSON description of a bookstore:</p>
188 <div class="informalexample">
189   <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
190     <tbody>
191       <tr>
192         <td class="listing_lines" align="right"><pre>1
193 2
194 3
195 4
196 5
197 6
198 7
199 8
200 9
201 10
202 11
203 12
204 13
205 14
206 15
207 16</pre></td>
208         <td class="listing_code"><pre class="programlisting"><span class="cbracket">{</span><span class="normal"> </span><span class="string">"store"</span><span class="symbol">:</span><span class="normal"> </span><span class="cbracket">{</span>
209 <span class="normal">    </span><span class="string">"book"</span><span class="symbol">:</span><span class="normal"> </span><span class="symbol">[</span>
210 <span class="normal">      </span><span class="cbracket">{</span><span class="normal"> </span><span class="string">"category"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"reference"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"author"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"Nigel Rees"</span><span class="symbol">,</span>
211 <span class="normal">        </span><span class="string">"title"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"Sayings of the Century"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"price"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"8.95"</span><span class="normal">  </span><span class="cbracket">}</span><span class="symbol">,</span>
212 <span class="normal">      </span><span class="cbracket">{</span><span class="normal"> </span><span class="string">"category"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"fiction"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"author"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"Evelyn Waugh"</span><span class="symbol">,</span>
213 <span class="normal">        </span><span class="string">"title"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"Sword of Honour"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"price"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"12.99"</span><span class="normal"> </span><span class="cbracket">}</span><span class="symbol">,</span>
214 <span class="normal">      </span><span class="cbracket">{</span><span class="normal"> </span><span class="string">"category"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"fiction"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"author"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"Herman Melville"</span><span class="symbol">,</span>
215 <span class="normal">        </span><span class="string">"title"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"Moby Dick"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"isbn"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"0-553-21311-3"</span><span class="symbol">,</span>
216 <span class="normal">        </span><span class="string">"price"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"8.99"</span><span class="normal"> </span><span class="cbracket">}</span><span class="symbol">,</span>
217 <span class="normal">      </span><span class="cbracket">{</span><span class="normal"> </span><span class="string">"category"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"fiction"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"author"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"J. R. R. Tolkien"</span><span class="symbol">,</span>
218 <span class="normal">        </span><span class="string">"title"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"The Lord of the Rings"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"isbn"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"0-395-19395-8"</span><span class="symbol">,</span>
219 <span class="normal">        </span><span class="string">"price"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"22.99"</span><span class="normal"> </span><span class="cbracket">}</span>
220 <span class="normal">    </span><span class="symbol">],</span>
221 <span class="normal">    </span><span class="string">"bicycle"</span><span class="symbol">:</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> </span><span class="string">"color"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"red"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"price"</span><span class="symbol">:</span><span class="normal"> </span><span class="string">"19.95"</span><span class="normal"> </span><span class="cbracket">}</span>
222 <span class="normal">  </span><span class="cbracket">}</span>
223 <span class="cbracket">}</span></pre></td>
224       </tr>
225     </tbody>
226   </table>
227 </div>
228
229 <p></p>
230 <p>We can parse the JSON using <a class="link" href="JsonParser.html" title="JsonParser"><span class="type">JsonParser</span></a>:</p>
231 <div class="informalexample">
232   <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
233     <tbody>
234       <tr>
235         <td class="listing_lines" align="right"><pre>1
236 2</pre></td>
237         <td class="listing_code"><pre class="programlisting"><span class="usertype">JsonParser</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">parser </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="JsonParser.html#json-parser-new">json_parser_new</a></span><span class="normal"> </span><span class="symbol">();</span>
238 <span class="function"><a href="JsonParser.html#json-parser-load-from-data">json_parser_load_from_data</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">parser</span><span class="symbol">,</span><span class="normal"> json_data</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">-</span><span class="number">1</span><span class="symbol">,</span><span class="normal"> NULL</span><span class="symbol">);</span></pre></td>
239       </tr>
240     </tbody>
241   </table>
242 </div>
243
244 <p></p>
245 <p>If we run the following code:</p>
246 <div class="informalexample">
247   <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
248     <tbody>
249       <tr>
250         <td class="listing_lines" align="right"><pre>1
251 2
252 3
253 4</pre></td>
254         <td class="listing_code"><pre class="programlisting"><span class="usertype">JsonNode</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">result</span><span class="symbol">;</span>
255 <span class="usertype">JsonPath</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">path </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="JsonPath.html#json-path-new">json_path_new</a></span><span class="normal"> </span><span class="symbol">();</span>
256 <span class="function"><a href="JsonPath.html#json-path-compile">json_path_compile</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">path</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"$.store..author"</span><span class="symbol">,</span><span class="normal"> NULL</span><span class="symbol">);</span>
257 <span class="normal">result </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="JsonPath.html#json-path-match">json_path_match</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">path</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="JsonParser.html#json-parser-get-root">json_parser_get_root</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">parser</span><span class="symbol">));</span></pre></td>
258       </tr>
259     </tbody>
260   </table>
261 </div>
262
263 <p></p>
264 <p>The result <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> will contain an array with all values of the
265 author member of the objects in the JSON tree. If we use a
266 <a class="link" href="JsonGenerator.html" title="JsonGenerator"><span class="type">JsonGenerator</span></a> to convert the <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> to a string and print it:</p>
267 <div class="informalexample">
268   <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
269     <tbody>
270       <tr>
271         <td class="listing_lines" align="right"><pre>1
272 2
273 3
274 4</pre></td>
275         <td class="listing_code"><pre class="programlisting"><span class="usertype">JsonGenerator</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">generator </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="JsonGenerator.html#json-generator-new">json_generator_new</a></span><span class="normal"> </span><span class="symbol">();</span>
276 <span class="function"><a href="JsonGenerator.html#json-generator-set-root">json_generator_set_root</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">generator</span><span class="symbol">,</span><span class="normal"> result</span><span class="symbol">);</span>
277 <span class="type">char</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">str </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="JsonGenerator.html#json-generator-to-data">json_generator_to_data</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">generator</span><span class="symbol">,</span><span class="normal"> NULL</span><span class="symbol">);</span>
278 <span class="function">g_print</span><span class="normal"> </span><span class="symbol">(</span><span class="string">"Results: %s</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> str</span><span class="symbol">);</span></pre></td>
279       </tr>
280     </tbody>
281   </table>
282 </div>
283
284 <p></p>
285 <p>The output will be:</p>
286 <div class="informalexample">
287   <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
288     <tbody>
289       <tr>
290         <td class="listing_lines" align="right"><pre>1</pre></td>
291         <td class="listing_code"><pre class="programlisting"><span class="symbol">[</span><span class="string">"Nigel Rees"</span><span class="symbol">,</span><span class="string">"Evelyn Waugh"</span><span class="symbol">,</span><span class="string">"Herman Melville"</span><span class="symbol">,</span><span class="string">"J. R. R. Tolkien"</span><span class="symbol">]</span></pre></td>
292       </tr>
293     </tbody>
294   </table>
295 </div>
296
297 <p></p>
298 <p><a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> is available since JSON-GLib 0.14</p>
299 </div>
300 </div>
301 <div class="refsect1">
302 <a name="JsonPath.functions_details"></a><h2>Functions</h2>
303 <div class="refsect2">
304 <a name="json-path-new"></a><h3>json_path_new ()</h3>
305 <pre class="programlisting"><a class="link" href="JsonPath.html" title="JsonPath"><span class="returnvalue">JsonPath</span></a> *
306 json_path_new (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
307 <p>Creates a new <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> instance.</p>
308 <p>Once created, the <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> object should be used with <a class="link" href="JsonPath.html#json-path-compile" title="json_path_compile ()"><code class="function">json_path_compile()</code></a>
309 and <a class="link" href="JsonPath.html#json-path-match" title="json_path_match ()"><code class="function">json_path_match()</code></a>.</p>
310 <div class="refsect3">
311 <a name="json-path-new.returns"></a><h4>Returns</h4>
312 <p> the newly created <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> instance. Use
313 <code class="function">g_object_unref()</code> to free the allocated resources when done. </p>
314 <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
315 </div>
316 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
317 </div>
318 <hr>
319 <div class="refsect2">
320 <a name="json-path-compile"></a><h3>json_path_compile ()</h3>
321 <pre class="programlisting"><span class="returnvalue">gboolean</span>
322 json_path_compile (<em class="parameter"><code><a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> *path</code></em>,
323                    <em class="parameter"><code>const <span class="type">char</span> *expression</code></em>,
324                    <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
325 <p>Validates and decomposes <em class="parameter"><code>expression</code></em>
326 .</p>
327 <p>A JSONPath expression must be compiled before calling <a class="link" href="JsonPath.html#json-path-match" title="json_path_match ()"><code class="function">json_path_match()</code></a>.</p>
328 <div class="refsect3">
329 <a name="json-path-compile.parameters"></a><h4>Parameters</h4>
330 <div class="informaltable"><table class="informaltable" width="100%" border="0">
331 <colgroup>
332 <col width="150px" class="parameters_name">
333 <col class="parameters_description">
334 <col width="200px" class="parameters_annotations">
335 </colgroup>
336 <tbody>
337 <tr>
338 <td class="parameter_name"><p>path</p></td>
339 <td class="parameter_description"><p>a <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a></p></td>
340 <td class="parameter_annotations"> </td>
341 </tr>
342 <tr>
343 <td class="parameter_name"><p>expression</p></td>
344 <td class="parameter_description"><p>a JSONPath expression</p></td>
345 <td class="parameter_annotations"> </td>
346 </tr>
347 <tr>
348 <td class="parameter_name"><p>error</p></td>
349 <td class="parameter_description"><p>return location for a <span class="type">GError</span>, or <code class="literal">NULL</code></p></td>
350 <td class="parameter_annotations"> </td>
351 </tr>
352 </tbody>
353 </table></div>
354 </div>
355 <div class="refsect3">
356 <a name="json-path-compile.returns"></a><h4>Returns</h4>
357 <p> <code class="literal">TRUE</code> on success; on error, <em class="parameter"><code>error</code></em>
358 will be set with
359 the <a class="link" href="JsonPath.html#JSON-PATH-ERROR:CAPS" title="JSON_PATH_ERROR"><code class="literal">JSON_PATH_ERROR</code></a> domain and a code from the <a class="link" href="JsonPath.html#JsonPathError" title="enum JsonPathError"><span class="type">JsonPathError</span></a>
360 enumeration, and <code class="literal">FALSE</code> will be returned</p>
361 </div>
362 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
363 </div>
364 <hr>
365 <div class="refsect2">
366 <a name="json-path-match"></a><h3>json_path_match ()</h3>
367 <pre class="programlisting"><a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="returnvalue">JsonNode</span></a> *
368 json_path_match (<em class="parameter"><code><a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> *path</code></em>,
369                  <em class="parameter"><code><a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> *root</code></em>);</pre>
370 <p>Matches the JSON tree pointed by <em class="parameter"><code>root</code></em>
371  using the expression compiled
372 into the <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a>.</p>
373 <p>The matching <a href="json-glib-JSON-Node.html#JsonNode-struct"><span class="type">JsonNodes</span></a> will be copied into a <a class="link" href="json-glib-JSON-Array.html#JsonArray"><span class="type">JsonArray</span></a> and
374 returned wrapped in a <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a>.</p>
375 <div class="refsect3">
376 <a name="json-path-match.parameters"></a><h4>Parameters</h4>
377 <div class="informaltable"><table class="informaltable" width="100%" border="0">
378 <colgroup>
379 <col width="150px" class="parameters_name">
380 <col class="parameters_description">
381 <col width="200px" class="parameters_annotations">
382 </colgroup>
383 <tbody>
384 <tr>
385 <td class="parameter_name"><p>path</p></td>
386 <td class="parameter_description"><p>a compiled <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a></p></td>
387 <td class="parameter_annotations"> </td>
388 </tr>
389 <tr>
390 <td class="parameter_name"><p>root</p></td>
391 <td class="parameter_description"><p>a <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a></p></td>
392 <td class="parameter_annotations"> </td>
393 </tr>
394 </tbody>
395 </table></div>
396 </div>
397 <div class="refsect3">
398 <a name="json-path-match.returns"></a><h4>Returns</h4>
399 <p> a newly-created <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> of type
400 <a class="link" href="json-glib-JSON-Node.html#JSON-NODE-ARRAY:CAPS"><code class="literal">JSON_NODE_ARRAY</code></a> containing an array of matching <a href="json-glib-JSON-Node.html#JsonNode-struct"><span class="type">JsonNodes</span></a>.
401 Use <a class="link" href="json-glib-JSON-Node.html#json-node-unref" title="json_node_unref ()"><code class="function">json_node_unref()</code></a> when done. </p>
402 <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
403 </div>
404 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
405 </div>
406 <hr>
407 <div class="refsect2">
408 <a name="json-path-query"></a><h3>json_path_query ()</h3>
409 <pre class="programlisting"><a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="returnvalue">JsonNode</span></a> *
410 json_path_query (<em class="parameter"><code>const <span class="type">char</span> *expression</code></em>,
411                  <em class="parameter"><code><a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> *root</code></em>,
412                  <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
413 <p>Queries a JSON tree using a JSONPath expression.</p>
414 <p>This function is a simple wrapper around <a class="link" href="JsonPath.html#json-path-new" title="json_path_new ()"><code class="function">json_path_new()</code></a>,
415 <a class="link" href="JsonPath.html#json-path-compile" title="json_path_compile ()"><code class="function">json_path_compile()</code></a> and <a class="link" href="JsonPath.html#json-path-match" title="json_path_match ()"><code class="function">json_path_match()</code></a>. It implicitly
416 creates a <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> instance, compiles <em class="parameter"><code>expression</code></em>
417  and
418 matches it against the JSON tree pointed by <em class="parameter"><code>root</code></em>
419 .</p>
420 <div class="refsect3">
421 <a name="json-path-query.parameters"></a><h4>Parameters</h4>
422 <div class="informaltable"><table class="informaltable" width="100%" border="0">
423 <colgroup>
424 <col width="150px" class="parameters_name">
425 <col class="parameters_description">
426 <col width="200px" class="parameters_annotations">
427 </colgroup>
428 <tbody>
429 <tr>
430 <td class="parameter_name"><p>expression</p></td>
431 <td class="parameter_description"><p>a JSONPath expression</p></td>
432 <td class="parameter_annotations"> </td>
433 </tr>
434 <tr>
435 <td class="parameter_name"><p>root</p></td>
436 <td class="parameter_description"><p>the root of a JSON tree</p></td>
437 <td class="parameter_annotations"> </td>
438 </tr>
439 <tr>
440 <td class="parameter_name"><p>error</p></td>
441 <td class="parameter_description"><p>return location for a <span class="type">GError</span>, or <code class="literal">NULL</code></p></td>
442 <td class="parameter_annotations"> </td>
443 </tr>
444 </tbody>
445 </table></div>
446 </div>
447 <div class="refsect3">
448 <a name="json-path-query.returns"></a><h4>Returns</h4>
449 <p> a newly-created <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> of type
450 <a class="link" href="json-glib-JSON-Node.html#JSON-NODE-ARRAY:CAPS"><code class="literal">JSON_NODE_ARRAY</code></a> containing an array of matching <a href="json-glib-JSON-Node.html#JsonNode-struct"><span class="type">JsonNodes</span></a>.
451 Use <a class="link" href="json-glib-JSON-Node.html#json-node-unref" title="json_node_unref ()"><code class="function">json_node_unref()</code></a> when done. </p>
452 <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
453 </div>
454 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
455 </div>
456 </div>
457 <div class="refsect1">
458 <a name="JsonPath.other_details"></a><h2>Types and Values</h2>
459 <div class="refsect2">
460 <a name="JsonPath-struct"></a><h3>JsonPath</h3>
461 <pre class="programlisting">typedef struct _JsonPath JsonPath;</pre>
462 <p>The <code class="literal">JsonPath</code> structure is an opaque object whose members cannot be
463 directly accessed except through the provided API.</p>
464 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
465 </div>
466 <hr>
467 <div class="refsect2">
468 <a name="JsonPathClass"></a><h3>JsonPathClass</h3>
469 <pre class="programlisting">typedef struct _JsonPathClass JsonPathClass;</pre>
470 <p>The <code class="literal">JsonPathClass</code> structure is an opaque object class whose members
471 cannot be directly accessed.</p>
472 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
473 </div>
474 <hr>
475 <div class="refsect2">
476 <a name="JSON-PATH-ERROR:CAPS"></a><h3>JSON_PATH_ERROR</h3>
477 <pre class="programlisting">#define JSON_PATH_ERROR         (json_path_error_quark ())
478 </pre>
479 <p>Error domain for <a class="link" href="JsonPath.html" title="JsonPath"><span class="type">JsonPath</span></a> errors</p>
480 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
481 </div>
482 <hr>
483 <div class="refsect2">
484 <a name="JsonPathError"></a><h3>enum JsonPathError</h3>
485 <p>Error code enumeration for the <a class="link" href="JsonPath.html#JSON-PATH-ERROR:CAPS" title="JSON_PATH_ERROR"><code class="literal">JSON_PATH_ERROR</code></a> domain.</p>
486 <div class="refsect3">
487 <a name="JsonPathError.members"></a><h4>Members</h4>
488 <div class="informaltable"><table class="informaltable" width="100%" border="0">
489 <colgroup>
490 <col width="300px" class="enum_members_name">
491 <col class="enum_members_description">
492 <col width="200px" class="enum_members_annotations">
493 </colgroup>
494 <tbody><tr>
495 <td class="enum_member_name"><p><a name="JSON-PATH-ERROR-INVALID-QUERY:CAPS"></a>JSON_PATH_ERROR_INVALID_QUERY</p></td>
496 <td class="enum_member_description">
497 <p>Invalid query</p>
498 </td>
499 <td class="enum_member_annotations"> </td>
500 </tr></tbody>
501 </table></div>
502 </div>
503 <p class="since">Since: <a class="link" href="ix08.html#api-index-0.14">0.14</a></p>
504 </div>
505 </div>
506 </div>
507 <div class="footer">
508 <hr>Generated by GTK-Doc V1.25.1</div>
509 </body>
510 </html>