JSON

JSON is a subset of Javascript that is specifically for data exchange. See http://www.json.org/ for the specification.

Relationship with YAML

With a little care, JSON is also a valid subset of YAML. All JSON is valid YAML if you take care to strip the comments, don't use single quoted strings, and ensure a space after the commas and colons.

See why's post for more details.

JSON instead of YAML

Pros: Javascript Compatibility

  • The browser can instantiate objects using eval (very fast) without any server side translations
  • We're already using JSON in a number of places
  • It doesn't do much, but you can reason through what it does

Cons: Requires work in Ruby and Rails

  • We have to handle serialization to/from the database ourselves (rather than rails doing it for us)
  • Doesn't support loopy data structures
  • Doesn't encode the classes of objects
  • Only allows string keys

YAML instead of JSON

Pros: Rails Compatibility, Ruby Compatibility

  • ActiveRecord makes serialized database fields work transparently
  • The differences between symbols and strings in hashes are preserved
  • Can transparently replace our current use of serialize

Cons: Requires work in Javascript, Must convert existing code

  • YAML must be converted to JSON before sending to the browser
  • Must rewrite everywhere we've already serialized
  • Would need to understand what we'd be saving
  • Less reliable as a serialization format because it's optimized for human readability
  • Doesn't handle utf-32

Use both YAML and JSON

Pros:

  • Already using both ... don't have to change things we've already written and that work
  • Don't even have to talk about it

Cons:

  • Additional complexity akin to technical debt


Decision

  • Which do we prefer for new development?
  • Is it worth switching any places we already use the other?


Retrieved from "http://aboutus.com/index.php?title=JSON&oldid=15200782"