3 These pages contain the API documentation of JSON for Modern C++, a C++11 header-only JSON class.
7 - @link nlohmann::basic_json `basic_json` class @endlink
8 - [Functions](functions_func.html)
10 - @link nlohmann::basic_json::dump dump @endlink -- value serialization
11 - @link nlohmann::basic_json::type type @endlink -- type of the value
12 - @link nlohmann::basic_json::is_primitive is_primitive @endlink,
13 @link nlohmann::basic_json::is_structured is_structured @endlink,
14 @link nlohmann::basic_json::is_null is_null @endlink,
15 @link nlohmann::basic_json::is_boolean is_boolean @endlink,
16 @link nlohmann::basic_json::is_number is_number @endlink,
17 @link nlohmann::basic_json::is_number_integer is_number_integer @endlink,
18 @link nlohmann::basic_json::is_number_unsigned is_number_unsigned @endlink,
19 @link nlohmann::basic_json::is_number_float is_number_float @endlink,
20 @link nlohmann::basic_json::is_object is_object @endlink,
21 @link nlohmann::basic_json::is_array is_array @endlink,
22 @link nlohmann::basic_json::is_string is_string @endlink,
23 @link nlohmann::basic_json::is_discarded is_discarded @endlink -- check for value type
24 - @link nlohmann::basic_json::operator value_t() const operator value_t @endlink -- type of the value (implicit conversion)
26 - @link nlohmann::basic_json::get get @endlink -- get a value
27 - @link nlohmann::basic_json::get_ptr get_ptr @endlink -- get a value pointer
28 - @link nlohmann::basic_json::get_ref get_ref @endlink -- get a value reference
29 - @link nlohmann::basic_json::operator ValueType() const operator ValueType @endlink -- get a value (implicit conversion)
30 - @link nlohmann::basic_json::value value @endlink -- get a value from an object and return default value if key is not present
32 - @link nlohmann::basic_json::parse_error parse_error @endlink for exceptions indicating a parse error
33 - @link nlohmann::basic_json::invalid_iterator invalid_iterator @endlink for exceptions indicating errors with iterators
34 - @link nlohmann::basic_json::type_error type_error @endlink for exceptions indicating executing a member function with a wrong type
35 - @link nlohmann::basic_json::out_of_range out_of_range @endlink for exceptions indicating access out of the defined range
36 - @link nlohmann::basic_json::other_error other_error @endlink for exceptions indicating other library errors
37 - lexicographical comparison operators
38 - @link nlohmann::basic_json::operator== operator== @endlink
39 - @link nlohmann::basic_json::operator!= operator!= @endlink
40 - @link nlohmann::basic_json::operator< operator<= @endlink
41 - @link nlohmann::basic_json::operator<= operator< @endlink
42 - @link nlohmann::basic_json::operator> operator> @endlink
43 - @link nlohmann::basic_json::operator>= operator>= @endlink
45 - @link nlohmann::basic_json::dump dump @endlink serialize to string
46 - @link nlohmann::basic_json::operator<<(std::ostream&, const basic_json &) operator<< @endlink serialize to stream
47 - deserialization / parsing
48 - @link nlohmann::basic_json::parse parse @endlink parse from input (string, file, etc.) and return JSON value
49 - @link nlohmann::basic_json::sax_parse sax_parse @endlink parse from input (string, file, etc.) and generate SAX events
50 - @link nlohmann::basic_json::operator>>(std::istream&, basic_json&) operator>> @endlink parse from stream
51 - @link nlohmann::basic_json::accept accept @endlink check for syntax errors without parsing
52 - @link nlohmann::json_sax SAX interface @endlink define a user-defined SAX event consumer
53 - @link nlohmann::basic_json::parser_callback_t callback interface @endlink register a callback to the parse function
54 - [binary formats](binary_formats.md):
55 - CBOR: @link nlohmann::basic_json::from_cbor from_cbor @endlink / @link nlohmann::basic_json::to_cbor to_cbor @endlink
56 - MessagePack: @link nlohmann::basic_json::from_msgpack from_msgpack @endlink / @link nlohmann::basic_json::to_msgpack to_msgpack @endlink
57 - UBJSON: @link nlohmann::basic_json::from_ubjson from_ubjson @endlink / @link nlohmann::basic_json::to_ubjson to_ubjson @endlink
58 - BSON: @link nlohmann::basic_json::from_bson from_bson @endlink / @link nlohmann::basic_json::to_bson to_bson @endlink
60 - @link nlohmann::basic_json::array_t arrays @endlink
61 - @link nlohmann::basic_json::object_t objects @endlink
62 - @link nlohmann::basic_json::string_t strings @endlink
63 - @link nlohmann::basic_json::boolean_t booleans @endlink
65 - @link nlohmann::basic_json::number_integer_t signed integers @endlink
66 - @link nlohmann::basic_json::number_unsigned_t unsigned integers @endlink
67 - @link nlohmann::basic_json::number_float_t floating-point @endlink
68 - further JSON standards
69 - @link nlohmann::json_pointer JSON Pointer @endlink (REF 6901)
70 - @link nlohmann::basic_json::patch JSON Patch @endlink (RFC 6902)
71 - @link nlohmann::basic_json::merge_patch JSON Merge Patch @endlink (RFC 7396)
73 # Container function overview
75 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.
77 Note that this table only lists those exceptions thrown due to the type. For instance, the @link nlohmann::basic_json::at(const typename object_t::key_type & key) `at` @endlink function will always throw a @link nlohmann::basic_json::type_error `json::type_error` @endlink exception when called for a string type. When called for an array, it *may* throw an @link nlohmann::basic_json::out_of_range `json::out_of_range` @endlink exception if the passed index is invalid.
81 <th rowspan="2">group</td>
82 <th rowspan="2">function</td>
83 <th colspan="6">JSON value type</th>
94 <td rowspan="8">iterators</td>
96 <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
97 <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
98 <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
99 <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
100 <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
101 <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink (returns `end()`)</td>
105 <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
106 <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
107 <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
108 <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
109 <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
110 <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink (returns `cend()`)</td>
114 <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
115 <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
116 <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
117 <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
118 <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
119 <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
123 <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
124 <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
125 <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
126 <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
127 <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
128 <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
132 <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
133 <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
134 <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
135 <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
136 <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
137 <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
141 <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
142 <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
143 <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
144 <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
145 <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
146 <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
150 <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
151 <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
152 <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
153 <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
154 <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
155 <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
159 <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
160 <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
161 <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
162 <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
163 <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
164 <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
167 <td rowspan="4">element<br>access</td>
169 <td class="ok_green">@link nlohmann::basic_json::at(const typename object_t::key_type & key) `at` @endlink</td>
170 <td class="ok_green">@link nlohmann::basic_json::at(size_type) `at` @endlink</td>
171 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (304)</td>
172 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (304)</td>
173 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (304)</td>
174 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (304)</td>
177 <td>`operator[]`</td>
178 <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type &key) `operator[]` @endlink</td>
179 <td class="ok_green">@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink</td>
180 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (305)</td>
181 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (305)</td>
182 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (305)</td>
183 <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>
187 <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
188 <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
189 <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
190 <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
191 <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
192 <td class="nok_throws">throws @link nlohmann::basic_json::invalid_iterator `json::invalid_iterator` @endlink (214)</td>
196 <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
197 <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
198 <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
199 <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
200 <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
201 <td class="nok_throws">throws @link nlohmann::basic_json::invalid_iterator `json::invalid_iterator` @endlink (214)</td>
204 <td rowspan="3">capacity</td>
206 <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
207 <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
208 <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
209 <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
210 <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
211 <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `true`)</td>
215 <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
216 <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
217 <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
218 <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
219 <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
220 <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `0`)</td>
224 <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
225 <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
226 <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
227 <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
228 <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
229 <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `0`)</td>
232 <td rowspan="7">modifiers</td>
234 <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
235 <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
236 <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
237 <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
238 <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
239 <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
243 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (309)</td>
244 <td class="ok_green">@link nlohmann::basic_json::insert `insert` @endlink</td>
245 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (309)</td>
246 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (309)</td>
247 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (309)</td>
248 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (309)</td>
252 <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
253 <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
254 <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
255 <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
256 <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
257 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (307)</td>
261 <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink</td>
262 <td class="ok_green">@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink</td>
263 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (308)</td>
264 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (308)</td>
265 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (308)</td>
266 <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>
269 <td>`emplace` / `emplace_back`</td>
270 <td class="ok_green">@link nlohmann::basic_json::emplace() `emplace` @endlink</td>
271 <td class="ok_green">@link nlohmann::basic_json::emplace_back() `emplace_back` @endlink</td>
272 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (311)</td>
273 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (311)</td>
274 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (311)</td>
275 <td class="ok_green">@link nlohmann::basic_json::emplace() `emplace` @endlink (creates object)<br>@link nlohmann::basic_json::emplace_back() `emplace_back` @endlink (creates array)</td>
279 <td class="ok_green">@link nlohmann::basic_json::update() `update` @endlink</td>
280 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (312)</td>
281 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (312)</td>
282 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (312)</td>
283 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (312)</td>
284 <td class="nok_throws">throws @link nlohmann::basic_json::type_error `json::type_error` @endlink (312)</td>
288 <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
289 <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
290 <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
291 <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
292 <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
293 <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
296 <td rowspan="3">lookup</td>
298 <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink</td>
299 <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
300 <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
301 <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
302 <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
303 <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
307 <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink</td>
308 <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
309 <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
310 <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
311 <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
312 <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
316 <td class="ok_green">@link nlohmann::basic_json::contains `contains` @endlink</td>
317 <td class="ok_green">@link nlohmann::basic_json::contains `contains` @endlink (returns `false`)</td>
318 <td class="ok_green">@link nlohmann::basic_json::contains `contains` @endlink (returns `false`)</td>
319 <td class="ok_green">@link nlohmann::basic_json::contains `contains` @endlink (returns `false`)</td>
320 <td class="ok_green">@link nlohmann::basic_json::contains `contains` @endlink (returns `false`)</td>
321 <td class="ok_green">@link nlohmann::basic_json::contains `contains` @endlink (returns `false`)</td>
325 @copyright Copyright © 2013-2019 Niels Lohmann. The code is licensed under the [MIT License](http://opensource.org/licenses/MIT).
327 @author [Niels Lohmann](http://nlohmann.me)
328 @see https://github.com/nlohmann/json to download the source code