Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Complete JSON gem compatibility (recreating objects) #34

tisba opened this Issue · 3 comments

4 participants


Currently yajl-ruby does not support building objects from parsed input like the JSON gem does. I've created a gist ( to illustrate how this works with the JSON gem. What's very nice about the functionality is that the JSON gem reconstructs the objects recursively (by calling json_create on the class corresponding to the json_class-field - which is configureable via JSON.create_id, IIRC).

This is a really useful feature, if you want to encode (nested) business objects for storing them to a document-oriented database, like CouchDB.

The top-level decoding and setting the correct classes can be done with this "hack":
obj = JSON.parse(obj)
obj = Object.const_get(obj["json_class"]).json_create(obj) if obj["json_class"]


thanks for the hack - would really like it if yajl did this natively +1


Sorry it's taken me so long to get back to you on this. I've decided against supporting arbitrary object creation because I'm of the stance that you should be fully aware of how objects are being created from data you receive over the wire or otherwise. Never trust what you're given ;)

@brianmario brianmario closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.