$30 off During Our Annual Pro Sale. View Details »

Deeper look at RFC7159 the JSON

Deeper look at RFC7159 the JSON

"Ninja" talk at Oedo Ruby Kaigi #04

Urabe Shyouhei

April 19, 2014

More Decks by Urabe Shyouhei

Other Decks in Programming


  1. Deeper look at RFC7159: the revised specification of JSON Urabe,

    Shyouhei. DeNA Co., Ltd.
  2. None
  3. New RFC to specify JSON was released last month!

  4. So I created a new gem

  5. None
  6. Why another JSON library?

  7. None
  8. None
  9. So a conforming JSON library … • MUST always generate

    JSON text that STRICTLY conforms the RFC, without ANY extensions such as NaNs. Otherwise that generator is not a conforming JSON library. • MUST always understand ALL expression that the RFC permits, NO MATTER HOW strange that specific expression is, or even impossible to represent in Ruby. Otherwise that parser is not a conforming JSON library. This is hard!
  10. How to tackle this situation

  11. None
  12. Line-by-line translation into racc and…

  13. None
  14. … and 100+ acceptance tests.

  15. Some interesting cases include:

  16. This is by design, but out of date.

  17. None
  18. None
  19. None
  20. None
  21. Should I stop using Yajl / Oj ? • I

    don't think so. • They are useful. Just having little bugs. All programms do so more or less. I don't want to point them at finger. • On the other hand, the library I created is strict-but-useless. It exhibits paranoia behaviour, too strict to reject converting most Ruby objects into JSON, while too tolerant to accept almost any texts, and most importantly, RUNS TOO SLOW.
  22. Fast enough to take 1.6+ secs for parsing 32KB

  23. Maybe JSON needs better trade-offs • Proper treatments of evil

    escapes, like [”\uD800”], is the nightmare that causes this slow-down. • Ignoring them only should greatly speed things up. • JSON spec might better be updated to explicitly forbid invalid sequences, even if they are escaped. • Everyone should stop generate such thing today.
  24. URLs to refer: • http://tools.ietf.org/html/rfc7159 • https://github.com/shyouhei/RFC7159 • https://rubygems.org/gems/RFC7159 Thank