Alexander.Iljushkin
Alexander.Iljushkin

Reputation: 4586

json parse error: invalid char in json text

I faced with a problem parsing json file with yajl-ruby. It shows an error of this kind:

'parse': lexical error: invalid char in json text. (Yajl::ParseError)

                   {     "inquiry":         {         "
(right here) ------^

I have tried to open a file with utf-8 encoding explicitly, but it doesn't help. The strange part of it that it raises error on a curly brace.

Upvotes: 1

Views: 1880

Answers (1)

Alexander.Iljushkin
Alexander.Iljushkin

Reputation: 4586

The reason was that I have opened a file encoded in UTF-8 with BOM. To fix this error, I was needed to open a file with following options:

File.open(@file, 'r:bom|utf-8')

Upvotes: 1

Related Questions