1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
6 <title>json-c: json_pointer.h File Reference</title>
7 <link href="tabs.css" rel="stylesheet" type="text/css"/>
8 <script type="text/javascript" src="jquery.js"></script>
9 <script type="text/javascript" src="dynsections.js"></script>
10 <link href="doxygen.css" rel="stylesheet" type="text/css" />
13 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
15 <table cellspacing="0" cellpadding="0">
17 <tr style="height: 56px;">
18 <td style="padding-left: 0.5em;">
19 <div id="projectname">json-c
20  <span id="projectnumber">0.17</span>
27 <!-- end header part -->
28 <!-- Generated by Doxygen 1.8.2 -->
29 <div id="navrow1" class="tabs">
31 <li><a href="index.html"><span>Main Page</span></a></li>
32 <li><a href="pages.html"><span>Related Pages</span></a></li>
33 <li><a href="annotated.html"><span>Data Structures</span></a></li>
34 <li class="current"><a href="files.html"><span>Files</span></a></li>
37 <div id="navrow2" class="tabs2">
39 <li><a href="files.html"><span>File List</span></a></li>
40 <li><a href="globals.html"><span>Globals</span></a></li>
46 <a href="#func-members">Functions</a> </div>
47 <div class="headertitle">
48 <div class="title">json_pointer.h File Reference</div> </div>
50 <div class="contents">
52 <p>JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree.
53 <a href="#details">More...</a></p>
54 <table class="memberdecls">
55 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
56 Functions</h2></td></tr>
57 <tr class="memitem:aff88937e32b0ba6ffbd07cb4b1919053"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int </td><td class="memItemRight" valign="bottom"><a class="el" href="json__pointer_8h.html#aff88937e32b0ba6ffbd07cb4b1919053">json_pointer_get</a> (struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *obj, const char *path, struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **res)</td></tr>
58 <tr class="separator:aff88937e32b0ba6ffbd07cb4b1919053"><td class="memSeparator" colspan="2"> </td></tr>
59 <tr class="memitem:af0ac03df64b215d05041e8007ed0233d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int </td><td class="memItemRight" valign="bottom"><a class="el" href="json__pointer_8h.html#af0ac03df64b215d05041e8007ed0233d">json_pointer_getf</a> (struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *obj, struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **res, const char *path_fmt,...)</td></tr>
60 <tr class="separator:af0ac03df64b215d05041e8007ed0233d"><td class="memSeparator" colspan="2"> </td></tr>
61 <tr class="memitem:aef0e651f63ce5ce35648503705e2586b"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int </td><td class="memItemRight" valign="bottom"><a class="el" href="json__pointer_8h.html#aef0e651f63ce5ce35648503705e2586b">json_pointer_set</a> (struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **obj, const char *path, struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *value)</td></tr>
62 <tr class="separator:aef0e651f63ce5ce35648503705e2586b"><td class="memSeparator" colspan="2"> </td></tr>
63 <tr class="memitem:a66f1f98a2ce085c19f6750193b4c726d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int </td><td class="memItemRight" valign="bottom"><a class="el" href="json__pointer_8h.html#a66f1f98a2ce085c19f6750193b4c726d">json_pointer_setf</a> (struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **obj, struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *value, const char *path_fmt,...)</td></tr>
64 <tr class="separator:a66f1f98a2ce085c19f6750193b4c726d"><td class="memSeparator" colspan="2"> </td></tr>
66 <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
67 <div class="textblock"><p>JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree. </p>
68 </div><h2 class="groupheader">Function Documentation</h2>
69 <a class="anchor" id="aff88937e32b0ba6ffbd07cb4b1919053"></a>
71 <div class="memproto">
72 <table class="memname">
74 <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_get </td>
76 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> * </td>
77 <td class="paramname"><em>obj</em>, </td>
80 <td class="paramkey"></td>
82 <td class="paramtype">const char * </td>
83 <td class="paramname"><em>path</em>, </td>
86 <td class="paramkey"></td>
88 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> ** </td>
89 <td class="paramname"><em>res</em> </td>
97 </div><div class="memdoc">
98 <p>Retrieves a JSON sub-object from inside another JSON object using the JSON pointer notation as defined in RFC 6901 <a href="https://tools.ietf.org/html/rfc6901">https://tools.ietf.org/html/rfc6901</a></p>
99 <p>The returned JSON sub-object is equivalent to parsing manually the 'obj' JSON tree ; i.e. it's not a new object that is created, but rather a pointer inside the JSON tree.</p>
100 <p>Internally, this is equivalent to doing a series of '<a class="el" href="json__object_8h.html#a1a097805abb53b4c8a60d573730a8939">json_object_object_get()</a>' and '<a class="el" href="json__object_8h.html#a676711a76545d4ec65cc75f100f5fd19">json_object_array_get_idx()</a>' along the given 'path'.</p>
101 <dl class="params"><dt>Parameters</dt><dd>
102 <table class="params">
103 <tr><td class="paramname">obj</td><td>the json_object instance/tree from where to retrieve sub-objects </td></tr>
104 <tr><td class="paramname">path</td><td>a (RFC6901) string notation for the sub-object to retrieve </td></tr>
105 <tr><td class="paramname">res</td><td>a pointer that stores a reference to the json_object associated with the given path</td></tr>
109 <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
113 <a class="anchor" id="af0ac03df64b215d05041e8007ed0233d"></a>
114 <div class="memitem">
115 <div class="memproto">
116 <table class="memname">
118 <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_getf </td>
120 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> * </td>
121 <td class="paramname"><em>obj</em>, </td>
124 <td class="paramkey"></td>
126 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> ** </td>
127 <td class="paramname"><em>res</em>, </td>
130 <td class="paramkey"></td>
132 <td class="paramtype">const char * </td>
133 <td class="paramname"><em>path_fmt</em>, </td>
136 <td class="paramkey"></td>
138 <td class="paramtype"> </td>
139 <td class="paramname"><em>...</em> </td>
147 </div><div class="memdoc">
148 <p>This is a variant of '<a class="el" href="json__pointer_8h.html#aff88937e32b0ba6ffbd07cb4b1919053">json_pointer_get()</a>' that supports printf() style arguments.</p>
149 <p>Variable arguments go after the 'path_fmt' parameter.</p>
150 <p>Example: json_pointer_getf(obj, res, "/foo/%d/%s", 0, "bar") This also means that you need to escape '' with '%' (just like in printf())</p>
151 <p>Please take into consideration all recommended 'printf()' format security aspects when using this function.</p>
152 <dl class="params"><dt>Parameters</dt><dd>
153 <table class="params">
154 <tr><td class="paramname">obj</td><td>the json_object instance/tree to which to add a sub-object </td></tr>
155 <tr><td class="paramname">res</td><td>a pointer that stores a reference to the json_object associated with the given path </td></tr>
156 <tr><td class="paramname">path_fmt</td><td>a printf() style format for the path</td></tr>
160 <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
164 <a class="anchor" id="aef0e651f63ce5ce35648503705e2586b"></a>
165 <div class="memitem">
166 <div class="memproto">
167 <table class="memname">
169 <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_set </td>
171 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> ** </td>
172 <td class="paramname"><em>obj</em>, </td>
175 <td class="paramkey"></td>
177 <td class="paramtype">const char * </td>
178 <td class="paramname"><em>path</em>, </td>
181 <td class="paramkey"></td>
183 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> * </td>
184 <td class="paramname"><em>value</em> </td>
192 </div><div class="memdoc">
193 <p>Sets JSON object 'value' in the 'obj' tree at the location specified by the 'path'. 'path' is JSON pointer notation as defined in RFC 6901 <a href="https://tools.ietf.org/html/rfc6901">https://tools.ietf.org/html/rfc6901</a></p>
194 <p>Note that 'obj' is a double pointer, mostly for the "" (empty string) case, where the entire JSON object would be replaced by 'value'. In the case of the "" path, the object at '*obj' will have it's refcount decremented with '<a class="el" href="json__object_8h.html#afabf61f932cd64a4122ca8092452eed5">json_object_put()</a>' and the 'value' object will be assigned to it.</p>
195 <p>For other cases (JSON sub-objects) ownership of 'value' will be transferred into '*obj' via '<a class="el" href="json__object_8h.html#a27bd808a022251059a43f1f6370441cd">json_object_object_add()</a>' & '<a class="el" href="json__object_8h.html#a1ac0ccdbc13a25da7d8b2dc9e421dfad">json_object_array_put_idx()</a>', so the only time the refcount should be decremented for 'value' is when the return value of '<a class="el" href="json__pointer_8h.html#aef0e651f63ce5ce35648503705e2586b">json_pointer_set()</a>' is negative (meaning the 'value' object did not get set into '*obj').</p>
196 <p>That also implies that '<a class="el" href="json__pointer_8h.html#aef0e651f63ce5ce35648503705e2586b">json_pointer_set()</a>' does not do any refcount incrementing. (Just that single decrement that was mentioned above).</p>
197 <dl class="params"><dt>Parameters</dt><dd>
198 <table class="params">
199 <tr><td class="paramname">obj</td><td>the json_object instance/tree to which to add a sub-object </td></tr>
200 <tr><td class="paramname">path</td><td>a (RFC6901) string notation for the sub-object to set in the tree </td></tr>
201 <tr><td class="paramname">value</td><td>object to set at path</td></tr>
205 <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
209 <a class="anchor" id="a66f1f98a2ce085c19f6750193b4c726d"></a>
210 <div class="memitem">
211 <div class="memproto">
212 <table class="memname">
214 <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_setf </td>
216 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> ** </td>
217 <td class="paramname"><em>obj</em>, </td>
220 <td class="paramkey"></td>
222 <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> * </td>
223 <td class="paramname"><em>value</em>, </td>
226 <td class="paramkey"></td>
228 <td class="paramtype">const char * </td>
229 <td class="paramname"><em>path_fmt</em>, </td>
232 <td class="paramkey"></td>
234 <td class="paramtype"> </td>
235 <td class="paramname"><em>...</em> </td>
243 </div><div class="memdoc">
244 <p>This is a variant of '<a class="el" href="json__pointer_8h.html#aef0e651f63ce5ce35648503705e2586b">json_pointer_set()</a>' that supports printf() style arguments.</p>
245 <p>Variable arguments go after the 'path_fmt' parameter.</p>
246 <p>Example: json_pointer_setf(obj, value, "/foo/%d/%s", 0, "bar") This also means that you need to escape '' with '%' (just like in printf())</p>
247 <p>Please take into consideration all recommended 'printf()' format security aspects when using this function.</p>
248 <dl class="params"><dt>Parameters</dt><dd>
249 <table class="params">
250 <tr><td class="paramname">obj</td><td>the json_object instance/tree to which to add a sub-object </td></tr>
251 <tr><td class="paramname">value</td><td>object to set at path </td></tr>
252 <tr><td class="paramname">path_fmt</td><td>a printf() style format for the path</td></tr>
256 <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
260 </div><!-- contents -->
261 <!-- start footer part -->
262 <hr class="footer"/><address class="footer"><small>
263 Generated on Sat Aug 12 2023 18:59:55 for json-c by  <a href="http://www.doxygen.org/index.html">
264 <img class="footer" src="doxygen.png" alt="doxygen"/>