Json: Support \n symbols in json string.

Created on 8 Sep 2017  路  2Comments  路  Source: nlohmann/json

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

question proposed fix

Most helpful comment

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

All 2 comments

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]}";

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhishupp picture zhishupp  路  4Comments

bassosimone picture bassosimone  路  3Comments

alienzj picture alienzj  路  4Comments

asmaloney picture asmaloney  路  4Comments

zkelo picture zkelo  路  3Comments