// instead, you could also write (which looks very similar to the JSON above)
// instead, you could also write (which looks very similar to the JSON above)
jsonj2={
jsonj2={
...
@@ -101,12 +101,24 @@ json j2 = {
...
@@ -101,12 +101,24 @@ json j2 = {
{"list",{1,0,2}},
{"list",{1,0,2}},
{"object",{
{"object",{
{"currency","USD"},
{"currency","USD"},
{"value","42.99"}
{"value",42.99}
}}
}}
};
};
```
```
Note that in all cases, you never need to "tell" the compiler which JSON value you want to use.
Note that in all theses cases, you never need to "tell" the compiler which JSON value you want to use. If you want to be explicit or express some edge cases, the functions `json::array` and `json::object` will help:
```cpp
// ways to express the empty array []
jsonempty_array_implicit={{}};
jsonempty_array_explicit=json::array();
// a way to express the empty object {}
jsonempty_object_explicit=json::object();
// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]]
@@ -207,6 +219,55 @@ for (json::iterator it = o.begin(); it != o.end(); ++it) {
...
@@ -207,6 +219,55 @@ for (json::iterator it = o.begin(); it != o.end(); ++it) {
}
}
```
```
### Conversion from STL containers
Any sequence container (`std::array`, `std::vector`, `std::deque`, `std::forward_list`, `std::list`) whose values can be used to construct JSON types (e.g., integers, floating point numbers, Booleans, string types, or again STL containers described in this section) can be used to create a JSON array. The same holds for similar associative containers (`std::set`, `std::multiset`, `std::unordered_set`, `std::unordered_multiset`), but in these cases the order of the elements of the array depends how the elements are ordered in the respective STL container.
Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys are can construct an `std::string` and whose values can be used to construct JSON types (see examples above) can be used to to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container.