Skip to content
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

Invoking is_array() function creates "null" value #77

Closed
drewpts opened this issue May 28, 2015 · 2 comments
Closed

Invoking is_array() function creates "null" value #77

drewpts opened this issue May 28, 2015 · 2 comments
Labels
solution: invalid the issue is not related to the library

Comments

@drewpts
Copy link

drewpts commented May 28, 2015

Hello.

 if (j[SUBPR_DESCR].is_array()) {
                if (j[SUBPR_DESCR].at(0).is_string() == false)
                    return json::parse(error_code + "Wrong values type of subprojects key!\"}");
            } else if (!j[SUBPR_DESCR].is_null() && !j[SUBPR_DESCR].is_array()) {
                return json::parse(error_code + "Corrupted or absent subprojects key!\"}");
            }

After invoking such function on json object data with key SUBPR_DESCR appearing with value "none".

2015-05-28 12 46 21
2015-05-28 12 46 31

[offtop] Lol, horrible char * to string casting at the bottom of image 🐹 [/offtop]

@drewpts
Copy link
Author

drewpts commented May 29, 2015

I just faced similar behaviour with method is_null(): if no value in object j under "subprojects" key invoking j["subprojects"].is_null() creates such value (see screen):
2015-05-29 13 35 50

Thank you for you attention!:)

@nlohmann
Copy link
Owner

What you try to do is to find out whether an object stores a value for a key. For that, you could try j.count("subprojects") == 0.

However, j["subprojects"] has a different semantics: If a key subprojects is stored in j, it returns a reference to that object. But if it does not, it creates a null value for that key. While this may make little sense when combined with is_null(), it helps to create objects easily, for instance j["foo]["bar"] = 1.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels May 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants