-
I am new to nlohmann::json and not a json expert but it appears that duplicate objects in an array are not being handled correctly (or I am doing something wrong).
And the output is:
Produces the expected output if the objects in the array are different. [compiler explorer gcc trunk nlohmann::json 3.6.0] |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
With the outer pair of braces, you create an array. With the next pair of braces, you create either an array or an object, depending on the further entries. In case of pairs where the first entry is a string, an object is created. Hence, you are trying to create the JSON value [ {"a": "b", "a": "b"} ] As there are no duplicate keys in JSON objects, this boils down to the value [ {"a": "b"} ] that you observe. See the example in https://nlohmann.github.io/json/api/basic_json/array/ for an example how to make a list of pairs. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response and for a really terrific and useful library. |
Beta Was this translation helpful? Give feedback.
With the outer pair of braces, you create an array. With the next pair of braces, you create either an array or an object, depending on the further entries. In case of pairs where the first entry is a string, an object is created. Hence, you are trying to create the JSON value
As there are no duplicate keys in JSON objects, this boils down to the value
that you observe. See the example in https://nlohmann.github.io/json/api/basic_json/array/ for an example how to make a list of pairs.