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

271 lines
15 KiB

  1. # JSON for Modern C++
  2. These pages contain the API documentation of JSON for Modern C++, a C++11 header-only JSON class.
  3. # Contents
  4. - @link nlohmann::basic_json `basic_json` class @endlink
  5. - [Functions](functions_func.html)
  6. - object inspection
  7. - @link nlohmann::basic_json::dump dump @endlink -- value serialization
  8. - @link nlohmann::basic_json::type type @endlink -- type of the value
  9. - @link nlohmann::basic_json::is_primitive is_primitive @endlink,
  10. @link nlohmann::basic_json::is_structured is_structured @endlink,
  11. @link nlohmann::basic_json::is_null is_null @endlink,
  12. @link nlohmann::basic_json::is_boolean is_boolean @endlink,
  13. @link nlohmann::basic_json::is_number is_number @endlink,
  14. @link nlohmann::basic_json::is_number_integer is_number_integer @endlink,
  15. @link nlohmann::basic_json::is_number_unsigned is_number_unsigned @endlink,
  16. @link nlohmann::basic_json::is_number_float is_number_float @endlink,
  17. @link nlohmann::basic_json::is_object is_object @endlink,
  18. @link nlohmann::basic_json::is_array is_array @endlink,
  19. @link nlohmann::basic_json::is_string is_string @endlink,
  20. @link nlohmann::basic_json::is_discarded is_discarded @endlink -- check for value type
  21. - @link nlohmann::basic_json::operator value_t() const operator value_t @endlink -- type of the value (implicit conversion)
  22. - value access
  23. - @link nlohmann::basic_json::get get @endlink -- get a value
  24. - @link nlohmann::basic_json::get_ptr get_ptr @endlink -- get a value pointer
  25. - @link nlohmann::basic_json::get_ref get_ref @endlink -- get a value reference
  26. - @link nlohmann::basic_json::operator ValueType() const operator ValueType @endlink -- get a value (implicit conversion)
  27. - lexicographical comparison operators
  28. - serialization
  29. - deserialization
  30. - Types
  31. - @link nlohmann::basic_json::array_t arrays @endlink
  32. - @link nlohmann::basic_json::object_t objects @endlink
  33. - @link nlohmann::basic_json::string_t strings @endlink
  34. - @link nlohmann::basic_json::boolean_t booleans @endlink
  35. - numbers
  36. - @link nlohmann::basic_json::number_integer_t signed integers @endlink
  37. - @link nlohmann::basic_json::number_unsigned_t unsigned integers @endlink
  38. - @link nlohmann::basic_json::number_float_t floating-point @endlink
  39. # Container function overview
  40. The container functions known from STL have been extended to support the different value types from JSON. However, not all functions can be applied to all value types. Note that the signature of some functions differ between the types; for instance, `at` may be called with either a string to address a key in an object or with an integer to address a value in an array.
  41. <table>
  42. <tr>
  43. <th rowspan="2">group</td>
  44. <th rowspan="2">function</td>
  45. <th colspan="6">JSON value type</th>
  46. </tr>
  47. <tr>
  48. <th>object</th>
  49. <th>array</th>
  50. <th>string</th>
  51. <th>number</th>
  52. <th>boolean</th>
  53. <th>null</th>
  54. </tr>
  55. <tr>
  56. <td rowspan="8">iterators</td>
  57. <td>`begin`</td>
  58. <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
  59. <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
  60. <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
  61. <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
  62. <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
  63. <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink (returns `end()`)</td>
  64. </tr>
  65. <tr>
  66. <td>`cbegin`</td>
  67. <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
  68. <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
  69. <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
  70. <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
  71. <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
  72. <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink (returns `cend()`)</td>
  73. </tr>
  74. <tr>
  75. <td>`end`</td>
  76. <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
  77. <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
  78. <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
  79. <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
  80. <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
  81. <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
  82. </tr>
  83. <tr>
  84. <td>`cend`</td>
  85. <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
  86. <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
  87. <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
  88. <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
  89. <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
  90. <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
  91. </tr>
  92. <tr>
  93. <td>`rbegin`</td>
  94. <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
  95. <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
  96. <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
  97. <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
  98. <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
  99. <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
  100. </tr>
  101. <tr>
  102. <td>`crbegin`</td>
  103. <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
  104. <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
  105. <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
  106. <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
  107. <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
  108. <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
  109. </tr>
  110. <tr>
  111. <td>`rend`</td>
  112. <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
  113. <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
  114. <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
  115. <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
  116. <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
  117. <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
  118. </tr>
  119. <tr>
  120. <td>`crend`</td>
  121. <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
  122. <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
  123. <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
  124. <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
  125. <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
  126. <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
  127. </tr>
  128. <tr>
  129. <td rowspan="4">element<br>access</td>
  130. <td>`at`</td>
  131. <td class="ok_green">@link nlohmann::basic_json::at(const typename object_t::key_type & key) `at` @endlink</td>
  132. <td class="ok_green">@link nlohmann::basic_json::at(size_type) `at` @endlink</td>
  133. <td class="nok_throws">throws `std::domain_error`</td>
  134. <td class="nok_throws">throws `std::domain_error`</td>
  135. <td class="nok_throws">throws `std::domain_error`</td>
  136. <td class="nok_throws">throws `std::domain_error`</td>
  137. </tr>
  138. <tr>
  139. <td>`operator[]`</td>
  140. <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type &key) `operator[]` @endlink</td>
  141. <td class="ok_green">@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink</td>
  142. <td class="nok_throws">throws `std::domain_error`</td>
  143. <td class="nok_throws">throws `std::domain_error`</td>
  144. <td class="nok_throws">throws `std::domain_error`</td>
  145. <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type & key) `operator[]` @endlink (creates object)<br>@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink (creates array)</td>
  146. </tr>
  147. <tr>
  148. <td>`front`</td>
  149. <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
  150. <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
  151. <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
  152. <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
  153. <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
  154. <td class="nok_throws">throws `std::out_of_range`</td>
  155. </tr>
  156. <tr>
  157. <td>`back`</td>
  158. <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
  159. <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
  160. <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
  161. <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
  162. <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
  163. <td class="nok_throws">throws `std::out_of_range`</td>
  164. </tr>
  165. <tr>
  166. <td rowspan="3">capacity</td>
  167. <td>`empty`</td>
  168. <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
  169. <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
  170. <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
  171. <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
  172. <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
  173. <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `true`)</td>
  174. </tr>
  175. <tr>
  176. <td>`size`</td>
  177. <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
  178. <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
  179. <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
  180. <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
  181. <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
  182. <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `0`)</td>
  183. </tr>
  184. <tr>
  185. <td>`max_size_`</td>
  186. <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
  187. <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
  188. <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
  189. <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
  190. <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
  191. <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `0`)</td>
  192. </tr>
  193. <tr>
  194. <td rowspan="5">modifiers</td>
  195. <td>`clear`</td>
  196. <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
  197. <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
  198. <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
  199. <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
  200. <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
  201. <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
  202. </tr>
  203. <tr>
  204. <td>`insert`</td>
  205. <td class="nok_throws">throws `std::domain_error`</td>
  206. <td class="ok_green">@link nlohmann::basic_json::insert `insert` @endlink</td>
  207. <td class="nok_throws">throws `std::domain_error`</td>
  208. <td class="nok_throws">throws `std::domain_error`</td>
  209. <td class="nok_throws">throws `std::domain_error`</td>
  210. <td class="nok_throws">throws `std::domain_error`</td>
  211. </tr>
  212. <tr>
  213. <td>`erase`</td>
  214. <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
  215. <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
  216. <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
  217. <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
  218. <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
  219. <td class="nok_throws">throws</td>
  220. </tr>
  221. <tr>
  222. <td>`push_back`</td>
  223. <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink</td>
  224. <td class="ok_green">@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink</td>
  225. <td class="nok_throws">throws `std::domain_error`</td>
  226. <td class="nok_throws">throws `std::domain_error`</td>
  227. <td class="nok_throws">throws `std::domain_error`</td>
  228. <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink (creates object)<br>@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink (creates array)</td>
  229. </tr>
  230. <tr>
  231. <td>`swap`</td>
  232. <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
  233. <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
  234. <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
  235. <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
  236. <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
  237. <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
  238. </tr>
  239. <tr>
  240. <td rowspan="2">lookup</td>
  241. <td>`find`</td>
  242. <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
  243. <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink</td>
  244. <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
  245. <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
  246. <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
  247. <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
  248. </tr>
  249. <tr>
  250. <td>`count`</td>
  251. <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
  252. <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink</td>
  253. <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
  254. <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
  255. <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
  256. <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
  257. </tr>
  258. </table>
  259. @copyright Copyright &copy; 2013-2016 Niels Lohmann. The code is licensed under the [MIT License](http://opensource.org/licenses/MIT).
  260. @author [Niels Lohmann](http://nlohmann.me)
  261. @see https://github.com/nlohmann/json to download the source code
  262. @version 2.0.0