Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deeper look at RFC7159 the JSON

Deeper look at RFC7159 the JSON

"Ninja" talk at Oedo Ruby Kaigi #04

Urabe Shyouhei

April 19, 2014
Tweet

More Decks by Urabe Shyouhei

Other Decks in Programming

Transcript

  1. Deeper look at RFC7159:
    the revised specification of JSON
    Urabe, Shyouhei.
    DeNA Co., Ltd.

    View full-size slide

  2. New RFC to specify JSON
    was released last month!

    View full-size slide

  3. So I created a new gem

    View full-size slide

  4. Why another JSON library?

    View full-size slide

  5. 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!

    View full-size slide

  6. How to tackle this situation

    View full-size slide

  7. Line-by-line
    translation
    into racc and…

    View full-size slide

  8. … and 100+
    acceptance tests.

    View full-size slide

  9. Some interesting cases include:

    View full-size slide

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

    View full-size slide

  11. 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.

    View full-size slide

  12. Fast enough to take 1.6+ secs for parsing 32KB

    View full-size slide

  13. 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.

    View full-size slide

  14. URLs to refer:

    http://tools.ietf.org/html/rfc7159

    https://github.com/shyouhei/RFC7159

    https://rubygems.org/gems/RFC7159
    Thank you!

    View full-size slide