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

"Expected valid escape sequence" for Windows Paths #99

Open
rhuankarlus opened this issue Jun 11, 2018 · 1 comment
Open

"Expected valid escape sequence" for Windows Paths #99

rhuankarlus opened this issue Jun 11, 2018 · 1 comment

Comments

@rhuankarlus
Copy link

When I try to parse a String that contains a Windows Path like "C:\MyPath\Wtv Folder" I get a Expected valid escape sequence error.

Example:

{
      "a": "foo",
      "b": "bar",
      "c": 1526,
      "d": "C:\\MyPath\\Wtv Folder"
}

I realized that the library is trying to find out which is the scape inserted but I want to avoid this behavior.

Do you guys noticed that?

@blongstreth
Copy link

Well, depends on what you are asking. If I treat your example document as a script file and read it in (or whatever), it works just fine (i.e. no errors). If I try to translate that to a Java String directly, then you need to escape it further, otherwise you will get the error you mentioned.

This works as expected:

final String jsonText = "{\n\t\"a\": \"foo\",\n\t\"b\": \"bar\",\n\t\"c\": 1526,\n\t\"d\": \"C:\\\\MyPath\\\\Wtv Folder\"\n}";

final JsonValue jsonValue = Json.parse(jsonText);

System.err.println("jsonText: " + jsonText);
System.err.println("jsonValue: " + jsonValue);

This does not work which is expected:

final String jsonText = "{\n\t\"a\": \"foo\",\n\t\"b\": \"bar\",\n\t\"c\": 1526,\n\t\"d\": \"C:\\MyPath\\Wtv Folder\"\n}";

final JsonValue jsonValue = Json.parse(jsonText);

System.err.println("jsonText: " + jsonText);
System.err.println("jsonValue: " + jsonValue);

As a sanity check, you can try one of the many JSON tools, linters. Here are a few:
JSON Checker
JSONLint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants