0

Yajl.load does not always throw on parse errors. For example:

irb(main):004:0>     Yajl.load('[[],"NOOOOOOOOOOOoooooooooooo!')

=> [[]]

It just ignored that tiny little detail at the end, and continues with what it got to that point. I want it to throw if the entire string as whole is bad, like the native JSON.parse method does:

irb(main):005:0> JSON.parse('[[],"NOOOOOOOOOOOoooooooooooo!')

JSON::ParserError: 399: unexpected token at '"NOOOOOOOOOOOoooooooooooo!'
from /home/me/.rvm/gems/ruby-1.9.3-p392/gems/json-1.7.5/lib/json/common.rb:155:in `parse'
from /home/me/.rvm/gems/ruby-1.9.3-p392/gems/json-1.7.5/lib/json/common.rb:155:in `parse'
from (irb):5

...

Is there any way to enforce a 'strict' mode in YAJL? Or will I need to run it through the native JSON.parse call each time to validate it if I wish to be sure I am operating on a legal JSON string?

Geremy
  • 2,415
  • 1
  • 23
  • 27
  • If you need it to raise an exception, and it doesn't, but JSON does, then why not use the JSON class? It seems like a simple choice. – the Tin Man Feb 25 '13 at 07:29

1 Answers1

1

This is an issue already open in the yajl project. Unfortunately, it has not been fixed yet.

Maybe give the issue a +1, or ask there why the issue is not handled nor responded to.

Beat Richartz
  • 9,474
  • 1
  • 33
  • 50