Search code examples
rubyjsonparsingyajl

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.


Solution

  • 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')