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

Support \n symbols in json string. #731

Closed
parfenuk opened this issue Sep 8, 2017 · 2 comments
Closed

Support \n symbols in json string. #731

parfenuk opened this issue Sep 8, 2017 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@parfenuk
Copy link

parfenuk commented Sep 8, 2017

Hi. First of all, thanks for the great job you performed all this time. Your tool turned out to be very helpful for me.

My question is: is there any endline symbols support planning in the near future or it violates standard json formatting rules?
For example, this code will crash the framework (C++):

string valueJSON = "{\"test\n\":[1,2,3]}";
json j = json::parse(valueJSON);

with an error: std::invalid_argument: parse error - unexpected '"'; expected string literal

and without \n the parser works ok.

Thanks.
Miroslav

@nlohmann
Copy link
Owner

nlohmann commented Sep 8, 2017

Newlines in strings must be escaped, see.

Therefore, you get a parse error. In version 3.0.0, the error description will be a bit more explanatory:

[json.exception.parse_error.101] parse error at 7: syntax error - invalid string: control character must be escaped; last read: '"test<U+000A>'; expected string literal

Your example should read:

string valueJSON = "{\"test\\n\":[1,2,3]}";

@parfenuk
Copy link
Author

parfenuk commented Sep 8, 2017

Oh, didn't notice this, thank you. Now it works perfectly.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Sep 8, 2017
@nlohmann nlohmann closed this as completed Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants