Skip to content
A streaming JSON parsing and encoding library for Ruby (C bindings to yajl)
C Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


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 or check out it's codes at

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 ='test.json', 'r')
hash = Yajl::Native.parse(json)

or maybe a StringIO

json_contents =
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

After you've got that, grab the latest version of Yajl itself from the Githubs at

After you have that installed, you should be able to install it like any other gem hosted here like so:

(more instructions here:

sudo gem install brianmario-yajl-ruby


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


This library is still being refined and should by no means be used in production. That being said, I'd like to invite you to clone/fork and test the crap out of it! ;)


While parsing is working for the most part, there are still some edge cases I need to tackle. Here's a list of things I need to get done to improve the awesomeness of this library.

  • Write up a test suite

  • Fix known parsing issues with certain JSON strings (Yajl itself works fine, it's the logic in this library that needs a little tweaking)

  • Write more docs

Something went wrong with that request. Please try again.