-
If I have a
If the key already exists I see this error: Is this expected behaviour? With Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
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 If you want the original
(Note that As we haven't published a 1.0.0 version, please let us know if you have different ideas/reasoning about the interface, we are still open to discussions and improvements. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation, it sounds reasonable. The I don't really have any strong preference either way. My only comment is that this wasn't clear to me from the documentation (or maybe I wasn't looking in the right spots?). Since this behaviour is different from how I appreciate the prompt response, and the library in general! |
Beta Was this translation helpful? Give feedback.
-
Thank you, and you are right that the documentation needs some improvement. We hope to get there once we will approach 1.0.0. |
Beta Was this translation helpful? Give feedback.
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 useemplace
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…