-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value function return empty object even if it exist #2086
Comments
This seems like a bug. A quick fix would be to pass |
I confirm that it works with Also it seem to fail if I want a null object by using:
|
Or we should explicitly specify the parameter as the object type: |
It should be ok to pass |
I had another look at this: The requirment for allowing code like json k = j.value("what", json::value_t::object); is that the type of the second argument, constexpr operator value_t() const noexcept
{
return m_type;
} So we check the object I now tend to agree with @dota17 that passing |
Describe what you want to achieve.
I need to get a default empty object in case an item do not exist in the specified json.
Describe what you tried.
Using the function
value
.Describe which system (OS, compiler) you are using.
GCC 9 on Ubuntu x64.
Describe which version of the library you are using (release version, develop branch).
I use develop branch.
Here is a simple example to demonstrate my question:
This output
k
as empty even if the item exist:However it works (
k
is filled with the good valuei'm here
) if I change the call ofvalue
with one of the following:json k = j.value<json>("what", json::value_t::object);
or
json k = j.value("what", json({}));
Is this the expected behavior?
The text was updated successfully, but these errors were encountered: