Home Bad JSON escape sequence: \v - the war stories
Post
Cancel

Bad JSON escape sequence: \v - the war stories

Introduction

Yesterday I did a small C# program for hash data in JSON. The are many files, which contains a lot of lines with JSON :) I was using Json.NET the most popular JSON library for .NET.

One in 200000000 lines (the number is correct) was bad. It was like this:

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

And I receive an exception: Bad JSON escape sequence: \v. Path 'data.str_1', line 1, position [number]

\v is equal to vertical tab which is |

Google results

The first thing I did was to search Google for ‘\v’ in JSON I was looking for phrase like this: bad JSON escape sequence: \v.. The first result was How to escape special characters in building a JSON string on StackOverflow. There I founded that:

See this list of special character used in JSON :

1
2
3
4
5
6
7
8
9
\b  Backspace (ascii code 08)
\f  Form feed (ascii code 0C)
\n  New line
\r  Carriage return
\t  Tab
\v  Vertical tab
\'  Apostrophe or single quote (only valid in single quoted json strings)
\"  Double quote (only valid in double quoted json strings)
\\  Backslash caracter

More over I found a source of above quote: https://www.json.com/json-object

Next step: question on SO about Newtosoft.Json

I created a new question on SO: Newtosoft.Json Bad JSON escape sequence: \v. Because I didn’t receive any useful answer I decided to fix Newtosoft.Json. My decision appears as a pull request Unexpectedly James Newton-King reject it and point me that \v is not valid according to spec on http://json.org/.

WHAT???

Moreover he is right. According to both: RFC 4627 and http://json.org/ which is same as ECMA-404 The JSON Data Interchange Standard the \v is not valid

Sum up

The unlucky escaped char took one day of my life. But I learn something new, so it is not a lost day

I also created a comment on https://www.json.com/json-object#object-with-strings and I hope they fix the definition.

The funny part is that some JSON validators accept \v some not :)

Below is a table with some JSON validators from first page on Google search

JSON validatorError on \vRemarks
http://jsonlint.com/Show error
http://www.freeformatter.com/json-validator.htmlShow validInformation sent
http://jsonformatter.curiousconcept.com/Show error
https://www.jsoneditoronline.org/Show error
http://codebeautify.org/jsonvalidateShow error
http://jsonviewer.stack.hu/Show valid
https://extendsclass.com/json-validator.htmlShow error
This post is licensed under CC BY 4.0 by the author.