https://github.com/chef/ffi-yajl
Ruby FFI gem wrapper around yajl2 library
https://github.com/chef/ffi-yajl
Keywords from Contributors
chef configuration-management discovery ohai deployment cfgmgt rubygems activejob activerecord mvc
Last synced: about 10 hours ago
JSON representation
Repository metadata
Ruby FFI gem wrapper around yajl2 library
- Host: GitHub
- URL: https://github.com/chef/ffi-yajl
- Owner: chef
- License: mit
- Created: 2013-10-24T06:16:58.000Z (almost 13 years ago)
- Default Branch: main
- Last Pushed: 2026-07-28T17:22:13.000Z (about 2 months ago)
- Last Synced: 2026-08-04T18:07:51.240Z (about 2 months ago)
- Language: Ruby
- Size: 807 KB
- Stars: 12
- Watchers: 12
- Forks: 24
- Open Issues: 5
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
README.md
FFI YAJL
ffi-yajl is a Ruby adapter for the 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.
How to Install
Warning if building through Omnibus, a preinstalled ffi-yajl and libyajl2-gem version not matching the bundled version of the project you're attempting to build (e.g., Chef) may cause:
cannot find -lyajldll: No such file or directory
If your build script ends up up in this state, a short term fix is gem uninstall -I libyajl2 before the failing bundle install
Install from the command-line:
gem install ffi-yajl
Or use a Gemfile:
gem 'ffi-yajl'
Supported Ruby VMs:
- Ruby 2.2+ and compatible rbx or jruby
Supported Distros:
- Ubuntu 10.04 through 14.10
- Debian 7.x
- RHEL/CentOS/Oracle 5.x/6.x/7.x
- Solaris 9/10/11 (gcc, sun compiler untested)
- AIX 6.x/7.x (gcc or xlc)
- Windows 2008r2/2012 (and Win2k/2k3 and consumer versions should work)
Basic Usage
Start by requiring it:
require 'ffi_yajl'
You can encode and parse with class objects:
options_hash = {}
json = FFI_Yajl::Encoder.encode( {"foo"=>["bar","baz"]}, options_hash )
hash = FFI_Yajl::Parser.parse( json, options_hash )
Or you can be more object oriented:
options_hash = {}
encoder = FFI_Yajl::Encoder.new( options_hash )
json = encoder.encode( {"foo"=>["bar","baz"]} )
parser = FFI_Yajl::Parser.new( options_hash )
hash = parser.parse( json )
Parser Options
:check_utf8:dont_validate_strings:symbolize_keys(default = false): JSON keys are parsed into symbols instead of strings.:symbolize_names(default = false): Alias for:symbolize_keys.:allow_trailing_garbage:allow_multiple_values:allow_partial_values:unique_key_checking(default = false): Will raise an exception if keys are repeated in hashes in the input JSON. Without this, repeated keys will silently replace the previous key.
Encoder Options
:pretty(default = false): Produces more human readable 'pretty' output.:validate_utf8(default = true): Will raise an exception when trying to encode strings that are invalid UTF-8. When set to false this still will produce valid UTF-8 JSON but will replace invalid characters.
Forcing FFI or C Extension
You can set the environment variable FORCE_FFI_YAJL to ext or ffi to control if the C extension or FFI bindings are used.
Yajl Library Packaging
This library prefers to use the embedded yajl 2.x C library packaged in the libyajl2 gem. In order to use the operating system yajl library (which must be yajl 2.x) the environment variable USE_SYSTEM_LIBYAJL2 can be set before installing or bundling libyajl2. This will force the libyajl2 gem to skip compiling its embedded library and the ffi-yajl gem will fallback to using the system yajl library.
No JSON Gem Compatiblity layer
This library does not offer a feature to patch #to_json methods into all the ruby classes similarly to the JSON gem or yajl-ruby's yajl/json_gem compatibility API. The differences in encoding between the JSON gem and the Yajl C library can produce different output on different systems and makes testing brittle. Such a feature will not be included. It was removed in this pull request and could be easily extracted to its own gem (we have no interest in maintaining that gem):
https://github.com/chef/ffi-yajl/pull/47/files
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 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 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.
License
Given that this draws heavily from the yajl-ruby sources, and could be considered a derivative work, the MIT License from that project has been preserved and this source code has deliberately not been dual licensed under Chef's typical Apache License. See the LICENSE file in this project.
Copyright
See COPYRIGHT.md.
Owner metadata
- Name: Progress Chef
- Login: chef
- Email: ops@chef.io
- Kind: organization
- Description:
- Website: https://www.chef.io/
- Location: United States of America
- Twitter: chef
- Company:
- Icon url: https://avatars.githubusercontent.com/u/29740?v=4
- Repositories: 245
- Last ynced at: 2023-04-10T00:51:04.360Z
- Profile URL: https://github.com/chef
GitHub Events
Total
- Create event: 10
- Delete event: 4
- Fork event: 3
- Issue comment event: 13
- Issues event: 2
- Pull request event: 15
- Pull request review comment event: 2
- Pull request review event: 17
- Push event: 35
- Watch event: 2
Last Year
- Create event: 5
- Delete event: 4
- Issue comment event: 7
- Issues event: 2
- Pull request event: 8
- Pull request review event: 9
- Push event: 17
Committers metadata
Last synced: 2 days ago
Total Commits: 595
Total Committers: 32
Avg Commits per committer: 18.594
Development Distribution Score (DDS): 0.21
Commits in past year: 39
Committers in past year: 10
Avg Commits per committer in past year: 3.9
Development Distribution Score (DDS) in past year: 0.564
| Name | Commits | |
|---|---|---|
| Lamont Granquist | l****t@s****g | 470 |
| Chef Expeditor | c****i@c****o | 27 |
| Tim Smith | t****h@c****o | 18 |
| Thomas Powell | t****l@p****m | 9 |
| Jaymala Sinha | j****a@c****o | 8 |
| skeshari12 | s****i@m****m | 7 |
| Stan Hu | s****u@g****m | 6 |
| Kouhei Sutou | k****u@c****m | 5 |
| Nandan Hegde | 2****3 | 5 |
| Olle Jonsson | o****n@g****m | 4 |
| cgunasree08 | C****e@p****m | 4 |
| tyler-ball | t****l@g****m | 4 |
| Chef Expeditor | e****r@c****o | 3 |
| Elan Ruusamäe | g****n@d****e | 2 |
| Jason Potkanski | e****n@y****m | 2 |
| Marc A. Paradise | m****e@g****m | 2 |
| Rishi Kumar Chawda | r****a | 2 |
| Tyler Vann-Campbell | t****r@b****m | 2 |
| danielsdeleo | d****n@c****o | 2 |
| nikhil2611 | n****2@g****m | 1 |
| Progress Copyright Bot | c****t@p****m | 1 |
| chef-expeditor[bot] | 4****] | 1 |
| brianLoomis | l****s@p****m | 1 |
| Vít Ondruch | v****h@r****m | 1 |
| Thom May | t****m@m****t | 1 |
| Sean Simmons | s****s@p****m | 1 |
| Phil Dibowitz | p****l@i****m | 1 |
| Lennart Brinkmann | l****a@g****m | 1 |
| Lance Albertson | l****e@o****g | 1 |
| John McCrae | j****e@p****m | 1 |
| and 2 more... | ||
Committer domains:
- progress.com: 6
- chef.io: 5
- thesparktree.com: 1
- osuosl.org: 1
- ipom.com: 1
- may.lt: 1
- redhat.com: 1
- buddy.com: 1
- delfi.ee: 1
- clear-code.com: 1
- msystechnologies.com: 1
- scriptkiddie.org: 1
Issue and Pull Request metadata
Last synced: 1 day ago
Total issues: 42
Total pull requests: 88
Average time to close issues: 2 months
Average time to close pull requests: about 1 month
Total issue authors: 31
Total pull request authors: 29
Average comments per issue: 1.86
Average comments per pull request: 1.45
Merged pull request: 67
Bot issues: 2
Bot pull requests: 0
Past year issues: 2
Past year pull requests: 10
Past year average time to close issues: about 2 months
Past year average time to close pull requests: about 2 months
Past year issue authors: 2
Past year pull request authors: 7
Past year average comments per issue: 1.5
Past year average comments per pull request: 0.1
Past year merged pull request: 5
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- lamont-granquist (10)
- dependabot-preview[bot] (2)
- h4ck3rm1k3 (2)
- crsuarez (1)
- anupamkakade (1)
- DavidTNguyen (1)
- tas50 (1)
- juliandunn (1)
- AnalogJ (1)
- cwimmer (1)
- logicminds (1)
- ddpdevang (1)
- adamedx (1)
- hsbt (1)
- iongion (1)
Top Pull Request Authors
- lamont-granquist (28)
- tas50 (5)
- kou (4)
- jaymalasinha (4)
- cgunasree08 (4)
- tpowell-progress (4)
- steakknife (3)
- olleolleolle (3)
- rishichawda (3)
- stanhu (3)
- dafyddcrosby (2)
- clintoncwolfe (2)
- sean-sype-simmons (2)
- danielsdeleo (2)
- voxik (2)
Top Issue Labels
- Type: Bug (11)
- Type: Enhancement (6)
- Status: Untriaged (5)
- Triage: Duplicate (2)
Top Pull Request Labels
- oss-standards (5)
- Expeditor: Bump Version Minor (4)
- Expeditor: Skip All (3)
- ai-assisted (2)
- Triage: Duplicate (2)
- do not merge (1)
Package metadata
- Total packages: 13
-
Total downloads:
- rubygems: 112,941,104 total
- Total docker downloads: 873,688,096
- Total dependent packages: 29 (may contain duplicates)
- Total dependent repositories: 2,315 (may contain duplicates)
- Total versions: 175
- Total maintainers: 5
gem.coop: ffi-yajl
Ruby FFI wrapper around YAJL 2.x
- Homepage: http://github.com/chef/ffi-yajl
- Documentation: http://www.rubydoc.info/gems/ffi-yajl/
- Licenses: MIT
- Latest release: 3.0.1 (published about 2 months ago)
- Last Synced: 2026-09-23T15:41:35.424Z (1 day ago)
- Versions: 81
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 56,470,552 Total
- Docker Downloads: 436,844,048
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.16%
- Downloads: 0.48%
- Maintainers (5)
pkgsrc-netbsd-x86_64-10.1-all: devel/ruby-ffi-yajl
Ruby FFI wrapper around YAJL 2.x
- Homepage: https://github.com/chef/ffi-yajl
- Documentation: https://pkgsrc.se/devel/ruby-ffi-yajl
- Licenses: mit
- Latest release: 2.5.0 (published 6 months ago)
- Last Synced: 2026-08-22T20:31:49.880Z (about 1 month ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 1.461%
- Forks count: 2.242%
- Stargazers count: 3.6%
rubygems.org: ffi-yajl
Ruby FFI wrapper around YAJL 2.x
- Homepage: http://github.com/chef/ffi-yajl
- Documentation: http://www.rubydoc.info/gems/ffi-yajl/
- Licenses: MIT
- Latest release: 3.0.1 (published about 2 months ago)
- Last Synced: 2026-09-23T15:41:35.412Z (1 day ago)
- Versions: 83
- Dependent Packages: 29
- Dependent Repositories: 2,315
- Downloads: 56,470,552 Total
- Docker Downloads: 436,844,048
-
Rankings:
- Docker downloads count: 0.332%
- Downloads: 0.502%
- Dependent repos count: 0.655%
- Dependent packages count: 0.803%
- Average: 3.989%
- Forks count: 5.898%
- Stargazers count: 15.74%
- Maintainers (5)
debian-11: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Documentation: https://packages.debian.org/bullseye/ruby-ffi-yajl
- Licenses:
- Latest release: 2.3.1-3 (published 8 months ago)
- Last Synced: 2026-08-02T20:03:43.965Z (about 2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-10: ruby-ffi-yajl
- Homepage: http://github.com/chef/ffi-yajl
- Documentation: https://packages.debian.org/buster/ruby-ffi-yajl
- Licenses:
- Latest release: 2.3.1-1 (published 8 months ago)
- Last Synced: 2026-03-13T19:03:40.567Z (7 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-23.04: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Status: removed
- Licenses:
- Latest release: 2.3.1-3build4 (published 8 months ago)
- Last Synced: 2026-07-27T07:03:55.463Z (about 2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-22.04: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Licenses:
- Latest release: 2.3.1-3build2 (published 7 months ago)
- Last Synced: 2026-03-13T22:41:59.328Z (7 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-23.10: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Licenses:
- Latest release: 2.3.1-3build4 (published 7 months ago)
- Last Synced: 2026-03-14T03:13:37.020Z (6 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-24.10: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Licenses:
- Latest release: 2.3.1-3build7 (published 8 months ago)
- Last Synced: 2026-03-09T17:05:25.580Z (7 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-12: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Documentation: https://packages.debian.org/bookworm/ruby-ffi-yajl
- Licenses:
- Latest release: 2.3.1-3 (published 7 months ago)
- Last Synced: 2026-03-13T03:29:16.064Z (7 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-24.04: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Licenses:
- Latest release: 2.3.1-3build6 (published 8 months ago)
- Last Synced: 2026-03-06T15:58:56.828Z (7 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-13: ruby-ffi-yajl
- Homepage: https://github.com/chef/ffi-yajl
- Documentation: https://packages.debian.org/trixie/ruby-ffi-yajl
- Licenses:
- Latest release: 2.3.1-3 (published 7 months ago)
- Last Synced: 2026-09-20T18:30:03.407Z (4 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
Dependencies
- chefstyle >= 0 development
- ffi >= 0 development
- pry ~> 0.9 development
- rack >= 0 development
- rake >= 0 development
- rake-compiler >= 0 development
- rspec >= 0 development
- actions/checkout v4 composite
- r7kamura/rubocop-problem-matchers-action v1 composite
- ruby/setup-ruby v1 composite
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
- cookstyle ~> 8.1 development
- libyajl2 >= 2.1
- yajl >= 0
Score: 27.008756977381733