summaryrefslogtreecommitdiff
path: root/README.md
blob: 0a60a3f10411e6447950dd3f563567650127473f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

[![Build Status](https://travis-ci.org/opscode/ffi-yajl.png)](https://travis-ci.org/opscode/ffi-yajl)  [![Code Climate](https://codeclimate.com/github/opscode/ffi-yajl.png)](https://codeclimate.com/github/opscode/ffi-yajl)

# FFI YAJL

ffi-yajl is a Ruby adapter for the [yajl](http://lloyd.github.io/yajl/)
JSON parser/generator library. ffi-yajl supports multiple Ruby C
extension mechanisms, including both MRI native extensions and FFI in
order to be compatible with as many Ruby implementations as possible
while providing good performance where possible.

## Basic Usage

```ruby
require 'ffi-yajl'
json_out = FFI_Yajl::Encoder.encode( { "foo" => [ "bar", "baz" ] } )
# => "{\"foo\":[\"bar\",\"baz\"]}"
data_in = FFI_Yajl::Parser.parse( json_out )
# => {"foo"=>["bar", "baz"]}
```

## Why This Instead of X?

yajl is the only JSON library we've found that has error messages that
meet our requirements. The stdlib json gem and oj (at the time we
started this project) have error messages like "invalid token at byte
1234," which are probably fine for server use, but in
[chef](https://github.com/chef/chef) we frequently deal with
user-written JSON documents, which means we need a good user experience
when encountering malformed JSON.

We previously used brianmario's
[yajl-ruby](https://github.com/brianmario/yajl-ruby) project, but we
wanted to be able to fallback to using FFI bindings to the C code (so we
could support non-MRI rubies) and we also needed some bug fixes in
yajl2, but the maintainer wasn't able to devote enough time to the
project to make these updates in a timeframe that worked for us.

## Thanks

This was initially going to be a clean rewrite of an ffi ruby wrapper around yajl2, but as it progressed more and more code was
pulled in from brianmario's existing yajl-ruby gem, particularly all the c extension code, lots of specs and the benchmarks.  And the
process of writing this would have been much more difficult without being able to draw heavily from already solved problems in
yajl-ruby.