Skip to content

Problem with duplicate objects in an array? #2402

Answered by nlohmann
slzatz asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by slzatz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2402 on September 25, 2020 08:06.