Path: | README.rdoc |
Last Update: | Mon Dec 20 21:43:30 +0000 2010 |
Lots of Ruby libraries utilize JSON parsing in some form, and everyone has their favorite JSON library. In order to best support multiple JSON parsers and libraries, multi_json is a general-purpose swappable JSON backend library. You use it like so:
require 'multi_json' MultiJson.engine = :yajl MultiJson.decode('{"abc":"def"}') # decoded using Yajl MultiJson.engine = :json_gem MultiJson.engine = MultiJson::Engines::JsonGem # equivalent to previous line MultiJson.encode({:abc => 'def'}) # encoded using the JSON gem
The engine setter takes either a symbol or a class (to allow for custom JSON parsers) that responds to both .decode and .encode at the class level.
MultiJSON tries to have intelligent defaulting. That is, if you have any of the supported engines already loaded, it will utilize them before attempting to load any. When loading, libraries are ordered by speed. First Yajl-Ruby, then the JSON gem, then ActiveSupport, then JSON pure.
Copyright (c) 2010 Michael Bleigh and Intridea, Inc. See LICENSE for details.