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

can't not parse "\\“ string #1123

Closed
wony-zheng opened this issue Jun 7, 2018 · 4 comments
Closed

can't not parse "\\“ string #1123

wony-zheng opened this issue Jun 7, 2018 · 4 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@wony-zheng
Copy link

json::parse("{\"c\": \"a\\a\"}") throw std::invalid_argument, msg: parse error - unexpected '"'

@nlohmann
Copy link
Owner

nlohmann commented Jun 7, 2018

Please try with the most recent released version - the error message should be more verbose then.

@abolz
Copy link
Contributor

abolz commented Jun 7, 2018

The error is expected: The string is first processed by the compiler to "{"c": "a\a"}" and a is not a valid escaped character according to the JSON grammar.

If you want a \ in the string literal you need to escape it twice: Once for the compiler and once for the JSON parser. This should work: json::parse("{\"c\": \"a\\\\a\"}") or json::parse(R"({"c": "a\\a"})")

@nlohmann
Copy link
Owner

nlohmann commented Jun 7, 2018

The most recent version has this diagnostic message:

[json.exception.parse_error.101] parse error at 10: syntax error - invalid string: forbidden character after backslash; last read: '"a\a'

I hope this makes the syntax error more clear.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jun 7, 2018
@nlohmann
Copy link
Owner

@wony-zheng Do you need further assistance on this?

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

3 participants