3

I am using Newtosoft.Json for parsing JSON, which is quite normal in C# :)

Unfortunately I got a json string like following to parse:

{"data": {"str_1": "' \u001e\v \u0003\u001f"\u0003\u001d %\b)\v#"}}

Calling JObject.Parse(aboveLine) gives me an error like Bad JSON escape sequence: \v. Path 'data.str_1', line 1, position [number]. \v is a sign for vertical line.

Is there a way how can I parse above json without exception?

Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • http://jsonlint.com/ – EZI Feb 19 '15 at 13:46
  • @EZI I don't understand your comment – Piotr Stapp Feb 19 '15 at 13:53
  • Garath, I say it is not a valid json. So You can't parse it. If you are getting it from some service ask them. – EZI Feb 19 '15 at 13:54
  • @EZI it is a valid JSON. Look at specification here: https://www.json.com/json-object or http://stackoverflow.com/questions/19176024/how-to-escape-special-characters-in-building-a-json-string – Piotr Stapp Feb 19 '15 at 17:16
  • Garath, Don't post me specs. Have you tried the link I posted. It is a json validator. Use it and see by yourself. Why don't you read and try the comments seriously. They are to help you. – EZI Feb 19 '15 at 17:42
  • @EZI I tried it. And it doesn't work for above string. But what should be my conclusion after this: my string is bad or jsonlint.com doesn't implement whole specification? That is why I check specification and send you comment with information. – Piotr Stapp Feb 19 '15 at 17:50
  • Then double-check. http://json2csharp.com/ or http://json.parser.online.fr/ What now? It is invalid. What is the source of it. If you, then check your code. If not, then nothing you can do about it (other than some silly string operations to fix it). – EZI Feb 19 '15 at 17:53
  • 1
    I understand that SOME parses claims that is not invalid. That is why I check specification. And I change parser: https://github.com/JamesNK/Newtonsoft.Json/pull/489 . I hope my pull request will be accepted. BTW http://www.freeformatter.com/json-validator.html claims it is a valid JSON – Piotr Stapp Feb 19 '15 at 18:02

2 Answers2

2

I checked the specification and I found that '\v' is a valid JSON. The specification is available here: https://www.json.com/json-object#object-with-strings

I also checked the source code an it does not support '\v'. That is why I created pull request which I hope will be merged into Newtonsoft.Json: https://github.com/JamesNK/Newtonsoft.Json/pull/489

Update

Unfortunately for me http://json.com is WRONG and \v is not a valid backlash char in JSON. The RFC 4627 specifies all of them and \v is not in it :( I added comment about this on http://json.com

Update 2

I described this story on my blog with all details. If you are interested just chek it out: http://stapp.space/bad-json-escape-sequence-v/

Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • Interesting. According to [json.org](http://json.org/) and the [ECMA JSON spec document](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf) `\v` is not valid in JSON strings. [RFC4627](http://www.ietf.org/rfc/rfc4627.txt) also does not have `\v`. – Brian Rogers Feb 19 '15 at 21:33
  • You are right. But I do not understand why json.com allows `\v` – Piotr Stapp Feb 20 '15 at 05:09
  • Perhaps json.com isn't the "official" spec. – Brian Rogers Feb 20 '15 at 14:34
  • @BrianRogers Unfortunately you are right. According to RFC 4627(JSON spec) `\v` is not a valid part of JSON – Piotr Stapp Feb 20 '15 at 15:00
  • json.org is the official/original website. – CodesInChaos Feb 20 '15 at 15:07
  • @CodesInChaos I know. But json.com have a bug which adds me day of work :( Anyway I add a comment. I hope they will fix it. Moreover some validators (like http://freeformatter.com/json-validator.html) accept this char – Piotr Stapp Feb 20 '15 at 15:20
0

Use \u000B (vertical tab) instead of \v and you'll have a valid JSON.

\v is a sign for vertical line

\u007C is the vertical line |

stefankmitph
  • 3,236
  • 2
  • 18
  • 22