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

null strings #1867

Closed
ETLang opened this issue Dec 11, 2019 · 4 comments
Closed

null strings #1867

ETLang opened this issue Dec 11, 2019 · 4 comments
Labels
state: needs more info the author of the issue needs to provide more details

Comments

@ETLang
Copy link

ETLang commented Dec 11, 2019

The following is valid JSON that fails to parse as a string:

{ "name" : null }

@t-b
Copy link
Contributor

t-b commented Dec 11, 2019

My application based on this library can parse it. Are you sure? What is the error message?

@nlohmann
Copy link
Owner

In order to asses your issue, we need the following information:

  • What is the issue you have?

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

  • What is the expected behavior?

  • And what is the actual behavior instead?

  • Which compiler and operating system are you using? Is it a supported compiler?

  • Did you use a released version of the library or the version from the develop branch?

  • If you experience a compilation error: can you compile and run the unit tests?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Dec 11, 2019
@ETLang
Copy link
Author

ETLang commented Dec 11, 2019

I'm using the single-include json.hpp, version 3.7.3.

Test case:
std::string testJson = "{ \"name\" : null }";
auto j = json::parse(testJson);
auto parsed = j.at("name").get<std::string>();

Actual Result:
Exception with message '[json.exception.type_error.302] type must be string, but is null'

Expected Result:
Tricky because std::string has no concept of null, but JSON strings definitely do. Maybe there's a way to manage this that I'm missing? My expectation is that null strings be translated into empty ones, but I can understand this not being universally preferable. Setting a flag on the parser could do the trick.

@ETLang
Copy link
Author

ETLang commented Dec 11, 2019

Nevermind, I'm dumb. I just added a is_null() check before parsing that field.

@ETLang ETLang closed this as completed Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

3 participants