CARVIEW |
Every repository with this icon (

Every repository with this icon (

Run the following if you haven't already:
gem sources -a https://gems.github.com
Install the gem(s):
sudo gem install brianmario-yajl-ruby
Description: | An extremely efficient streaming JSON parsing and encoding library. Ruby C bindings to Yajl edit |
Homepage: | https://rdoc.info/projects/brianmario/yajl-ruby edit |
Public Clone URL: |
git://github.com/brianmario/yajl-ruby.git
Give this clone URL to anyone.
git clone git://github.com/brianmario/yajl-ruby.git
|
Your Clone URL: |
Use this clone URL yourself.
git clone git@github.com:brianmario/yajl-ruby.git
|
name | age | message | |
---|---|---|---|
![]() |
.gitignore | Loading commit data... ![]() |
|
![]() |
MIT-LICENSE | Sun Apr 19 17:11:50 -0700 2009 | adding license [brianmario] |
![]() |
README.rdoc | ||
![]() |
Rakefile | ||
![]() |
VERSION.yml | ||
![]() |
benchmark/ | ||
![]() |
ext/ | ||
![]() |
yajl-ruby.gemspec |
YAJL C Bindings for Ruby (work in progress)
This gem (although not in gem form just yet) is a C binding to the excellent YAJL JSON parsing library.
You can read more info at the projects website lloydforge.org/projects/yajl or check out it’s codes at github.com/lloyd/yajl.
Example of use
First, you’re probably gonna want to include it:
include 'yajl'
Then maybe parse some JSON from:
a File IO
json_contents = File.new('test.json', 'r') hash = Yajl::Native.parse(json)
or maybe a StringIO
json_contents = StringIO.new hash = Yajl::Native.parse(json)
or maybe STDIN
cat someJsonFile.json | ruby -ryajl -e "puts Yajl::Native.parse(STDIN).inspect"
There are a lot more possibilities, some of which I’m going to write other gems/plugins for.
Some ideas are parsing logs in JSON format, an ActiveSupport patch, Rack middleware, use with ohai, JSON API clients, etc…
How to install
First, Yajl uses CMake to build itself (yes, the author realizes this isn’t the norm for open source and is willing and ready to accept patches, fork away kids!) so you’ll need to grab it first from www.cmake.org.
After you’ve got that, grab the latest version of Yajl itself from the Githubs at github.com/lloyd/yajl.
After you have that installed, you should be able to install it like any other gem hosted here like so:
(more instructions here: gems.github.com)
sudo gem install brianmario-yajl-ruby
Benchmarks
I’ll update this readme with some actual data soon.
After I finished implementation - this library performs close to the same as the current JSON.parse (C gem) does on small/medium files.
But on larger files, and higher amounts of iteration, this library was around 2x faster than JSON.parse.
The main benefit of this library is in it’s memory usage.
Since it’s able to parse the stream in chunks, it’s memory requirements are very, very low.
Again, I’ll post some actual data on this; but in my testing here’s what my ruby executable was using to parse a 10MB JSON file 100 times:
JSON.parse ~60MB Yajl::Native.parse ~30MB