Project

General

Profile

Bug #8742

JSON.parse can not handle tab in string

Added by joejack (Joe Jack) about 6 years ago. Updated about 6 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p194 (2012-04-20) [x86_64-linux]
[ruby-core:<unknown>]

Description

The following JSON file:

{
"I am tab": " "

}

does not parse when running the script:

require 'json'

JSON.parse IO::read 'tab.json'

the error message is:

/usr/local/lib/ruby/1.9.1/json/common.rb:148:in parse': 743: unexpected token at '{ (JSON::ParserError)
"I am tab": " "
}
'
from /usr/local/lib/ruby/1.9.1/json/common.rb:148:in
parse'

from parse.rb:2:in `'

Taking out the quoted tab solves the problem.
If there is a quoted tab in a file, the error message shows the entire document!

History

Updated by jacknagel (Jack Nagel) about 6 years ago

I don't think literal tabs are allowed in strings, per the JSON spec.

Updated by henrikhodne (Henrik Hodne) about 6 years ago

=begin
Confirm that tabs are not allowed in JSON strings according to the spec ((())).

Only characters that can be included unquoted are (({0x20}))-(({0x21})), (({0x23}))-(({0x5B})) and (({0x5D}))-(({0x10FFFF})).

I do agree that the error message is a little confusing, though.
=end

Updated by naruse (Yui NARUSE) about 6 years ago

  • Status changed from Open to Rejected

Also available in: Atom PDF