Skip to content

emplace throws exception if key already exists #58

Answered by d-frey
hoytech asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, this is the intended behavior.

Our rationale is: A JSON value will always be a hybrid between different things as it is a union type. It has a (partial) map-like interface, a (partial) vector-like interface and a bunch of other methods.

If you use the direct interface of value, you'll get some "support" for what we consider reasonable behavior for a JSON value. In this case, you will get an exception if you use emplace with a duplicate key. We thought about this in the past and decided that it is the most commonly useful behavior for that method.

If you want the original map interface, you can always access the embedded map (given that the value currently stores a JSON object) and us…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by d-frey
Comment options

You must be logged in to vote
0 replies
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 #58 on December 20, 2020 18:51.