You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

json__pointer_8h.html 16 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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">
  3. <head>
  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" />
  11. </head>
  12. <body>
  13. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  14. <div id="titlearea">
  15. <table cellspacing="0" cellpadding="0">
  16. <tbody>
  17. <tr style="height: 56px;">
  18. <td style="padding-left: 0.5em;">
  19. <div id="projectname">json-c
  20. &#160;<span id="projectnumber">0.17</span>
  21. </div>
  22. </td>
  23. </tr>
  24. </tbody>
  25. </table>
  26. </div>
  27. <!-- end header part -->
  28. <!-- Generated by Doxygen 1.8.2 -->
  29. <div id="navrow1" class="tabs">
  30. <ul class="tablist">
  31. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  32. <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  33. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  34. <li class="current"><a href="files.html"><span>Files</span></a></li>
  35. </ul>
  36. </div>
  37. <div id="navrow2" class="tabs2">
  38. <ul class="tablist">
  39. <li><a href="files.html"><span>File&#160;List</span></a></li>
  40. <li><a href="globals.html"><span>Globals</span></a></li>
  41. </ul>
  42. </div>
  43. </div><!-- top -->
  44. <div class="header">
  45. <div class="summary">
  46. <a href="#func-members">Functions</a> </div>
  47. <div class="headertitle">
  48. <div class="title">json_pointer.h File Reference</div> </div>
  49. </div><!--header-->
  50. <div class="contents">
  51. <p>JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree.
  52. <a href="#details">More...</a></p>
  53. <table class="memberdecls">
  54. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
  55. Functions</h2></td></tr>
  56. <tr class="memitem:aff88937e32b0ba6ffbd07cb4b1919053"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int&#160;</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>
  57. <tr class="separator:aff88937e32b0ba6ffbd07cb4b1919053"><td class="memSeparator" colspan="2">&#160;</td></tr>
  58. <tr class="memitem:af0ac03df64b215d05041e8007ed0233d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int&#160;</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>
  59. <tr class="separator:af0ac03df64b215d05041e8007ed0233d"><td class="memSeparator" colspan="2">&#160;</td></tr>
  60. <tr class="memitem:aef0e651f63ce5ce35648503705e2586b"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int&#160;</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>
  61. <tr class="separator:aef0e651f63ce5ce35648503705e2586b"><td class="memSeparator" colspan="2">&#160;</td></tr>
  62. <tr class="memitem:a66f1f98a2ce085c19f6750193b4c726d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int&#160;</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>
  63. <tr class="separator:a66f1f98a2ce085c19f6750193b4c726d"><td class="memSeparator" colspan="2">&#160;</td></tr>
  64. </table>
  65. <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
  66. <div class="textblock"><p>JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree. </p>
  67. </div><h2 class="groupheader">Function Documentation</h2>
  68. <a class="anchor" id="aff88937e32b0ba6ffbd07cb4b1919053"></a>
  69. <div class="memitem">
  70. <div class="memproto">
  71. <table class="memname">
  72. <tr>
  73. <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_get </td>
  74. <td>(</td>
  75. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *&#160;</td>
  76. <td class="paramname"><em>obj</em>, </td>
  77. </tr>
  78. <tr>
  79. <td class="paramkey"></td>
  80. <td></td>
  81. <td class="paramtype">const char *&#160;</td>
  82. <td class="paramname"><em>path</em>, </td>
  83. </tr>
  84. <tr>
  85. <td class="paramkey"></td>
  86. <td></td>
  87. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **&#160;</td>
  88. <td class="paramname"><em>res</em>&#160;</td>
  89. </tr>
  90. <tr>
  91. <td></td>
  92. <td>)</td>
  93. <td></td><td></td>
  94. </tr>
  95. </table>
  96. </div><div class="memdoc">
  97. <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>
  98. <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>
  99. <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>
  100. <dl class="params"><dt>Parameters</dt><dd>
  101. <table class="params">
  102. <tr><td class="paramname">obj</td><td>the json_object instance/tree from where to retrieve sub-objects </td></tr>
  103. <tr><td class="paramname">path</td><td>a (RFC6901) string notation for the sub-object to retrieve </td></tr>
  104. <tr><td class="paramname">res</td><td>a pointer that stores a reference to the json_object associated with the given path</td></tr>
  105. </table>
  106. </dd>
  107. </dl>
  108. <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
  109. </div>
  110. </div>
  111. <a class="anchor" id="af0ac03df64b215d05041e8007ed0233d"></a>
  112. <div class="memitem">
  113. <div class="memproto">
  114. <table class="memname">
  115. <tr>
  116. <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_getf </td>
  117. <td>(</td>
  118. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *&#160;</td>
  119. <td class="paramname"><em>obj</em>, </td>
  120. </tr>
  121. <tr>
  122. <td class="paramkey"></td>
  123. <td></td>
  124. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **&#160;</td>
  125. <td class="paramname"><em>res</em>, </td>
  126. </tr>
  127. <tr>
  128. <td class="paramkey"></td>
  129. <td></td>
  130. <td class="paramtype">const char *&#160;</td>
  131. <td class="paramname"><em>path_fmt</em>, </td>
  132. </tr>
  133. <tr>
  134. <td class="paramkey"></td>
  135. <td></td>
  136. <td class="paramtype">&#160;</td>
  137. <td class="paramname"><em>...</em>&#160;</td>
  138. </tr>
  139. <tr>
  140. <td></td>
  141. <td>)</td>
  142. <td></td><td></td>
  143. </tr>
  144. </table>
  145. </div><div class="memdoc">
  146. <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>
  147. <p>Variable arguments go after the 'path_fmt' parameter.</p>
  148. <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>
  149. <p>Please take into consideration all recommended 'printf()' format security aspects when using this function.</p>
  150. <dl class="params"><dt>Parameters</dt><dd>
  151. <table class="params">
  152. <tr><td class="paramname">obj</td><td>the json_object instance/tree to which to add a sub-object </td></tr>
  153. <tr><td class="paramname">res</td><td>a pointer that stores a reference to the json_object associated with the given path </td></tr>
  154. <tr><td class="paramname">path_fmt</td><td>a printf() style format for the path</td></tr>
  155. </table>
  156. </dd>
  157. </dl>
  158. <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
  159. </div>
  160. </div>
  161. <a class="anchor" id="aef0e651f63ce5ce35648503705e2586b"></a>
  162. <div class="memitem">
  163. <div class="memproto">
  164. <table class="memname">
  165. <tr>
  166. <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_set </td>
  167. <td>(</td>
  168. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **&#160;</td>
  169. <td class="paramname"><em>obj</em>, </td>
  170. </tr>
  171. <tr>
  172. <td class="paramkey"></td>
  173. <td></td>
  174. <td class="paramtype">const char *&#160;</td>
  175. <td class="paramname"><em>path</em>, </td>
  176. </tr>
  177. <tr>
  178. <td class="paramkey"></td>
  179. <td></td>
  180. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *&#160;</td>
  181. <td class="paramname"><em>value</em>&#160;</td>
  182. </tr>
  183. <tr>
  184. <td></td>
  185. <td>)</td>
  186. <td></td><td></td>
  187. </tr>
  188. </table>
  189. </div><div class="memdoc">
  190. <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>
  191. <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>
  192. <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>' &amp; '<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>
  193. <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>
  194. <dl class="params"><dt>Parameters</dt><dd>
  195. <table class="params">
  196. <tr><td class="paramname">obj</td><td>the json_object instance/tree to which to add a sub-object </td></tr>
  197. <tr><td class="paramname">path</td><td>a (RFC6901) string notation for the sub-object to set in the tree </td></tr>
  198. <tr><td class="paramname">value</td><td>object to set at path</td></tr>
  199. </table>
  200. </dd>
  201. </dl>
  202. <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
  203. </div>
  204. </div>
  205. <a class="anchor" id="a66f1f98a2ce085c19f6750193b4c726d"></a>
  206. <div class="memitem">
  207. <div class="memproto">
  208. <table class="memname">
  209. <tr>
  210. <td class="memname"><a class="el" href="printbuf_8h.html#a2a31d5c00f3a4712f2d5d62aee66344e">JSON_EXPORT</a> int json_pointer_setf </td>
  211. <td>(</td>
  212. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> **&#160;</td>
  213. <td class="paramname"><em>obj</em>, </td>
  214. </tr>
  215. <tr>
  216. <td class="paramkey"></td>
  217. <td></td>
  218. <td class="paramtype">struct <a class="el" href="json__types_8h.html#af27907ced0f5a43409ad96430fe0f914">json_object</a> *&#160;</td>
  219. <td class="paramname"><em>value</em>, </td>
  220. </tr>
  221. <tr>
  222. <td class="paramkey"></td>
  223. <td></td>
  224. <td class="paramtype">const char *&#160;</td>
  225. <td class="paramname"><em>path_fmt</em>, </td>
  226. </tr>
  227. <tr>
  228. <td class="paramkey"></td>
  229. <td></td>
  230. <td class="paramtype">&#160;</td>
  231. <td class="paramname"><em>...</em>&#160;</td>
  232. </tr>
  233. <tr>
  234. <td></td>
  235. <td>)</td>
  236. <td></td><td></td>
  237. </tr>
  238. </table>
  239. </div><div class="memdoc">
  240. <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>
  241. <p>Variable arguments go after the 'path_fmt' parameter.</p>
  242. <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>
  243. <p>Please take into consideration all recommended 'printf()' format security aspects when using this function.</p>
  244. <dl class="params"><dt>Parameters</dt><dd>
  245. <table class="params">
  246. <tr><td class="paramname">obj</td><td>the json_object instance/tree to which to add a sub-object </td></tr>
  247. <tr><td class="paramname">value</td><td>object to set at path </td></tr>
  248. <tr><td class="paramname">path_fmt</td><td>a printf() style format for the path</td></tr>
  249. </table>
  250. </dd>
  251. </dl>
  252. <dl class="section return"><dt>Returns</dt><dd>negative if an error (or not found), or 0 if succeeded </dd></dl>
  253. </div>
  254. </div>
  255. </div><!-- contents -->
  256. <!-- start footer part -->
  257. <hr class="footer"/><address class="footer"><small>
  258. Generated on Sat Aug 12 2023 18:59:55 for json-c by &#160;<a href="http://www.doxygen.org/index.html">
  259. <img class="footer" src="doxygen.png" alt="doxygen"/>
  260. </a> 1.8.2
  261. </small></address>
  262. </body>
  263. </html>

No Description