{"id":15649232,"url":"https://github.com/jhawthorn/rapidjson-ruby","last_synced_at":"2025-04-04T20:14:50.577Z","repository":{"id":136253721,"uuid":"477911629","full_name":"jhawthorn/rapidjson-ruby","owner":"jhawthorn","description":"A fast JSON library for Ruby","archived":false,"fork":false,"pushed_at":"2025-02-13T17:20:53.000Z","size":781,"stargazers_count":56,"open_issues_count":4,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-28T19:12:30.986Z","etag":null,"topics":["json","rapidjson","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jhawthorn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-04T23:47:01.000Z","updated_at":"2025-03-23T09:43:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"aa639bda-fa59-49ad-8eb5-36c6eeebec1d","html_url":"https://github.com/jhawthorn/rapidjson-ruby","commit_stats":{"total_commits":107,"total_committers":4,"mean_commits":26.75,"dds":"0.13084112149532712","last_synced_commit":"518818e6768c516f18cd78b095e603bf8b323bd6"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Frapidjson-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Frapidjson-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Frapidjson-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Frapidjson-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhawthorn","download_url":"https://codeload.github.com/jhawthorn/rapidjson-ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242680,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","rapidjson","ruby"],"created_at":"2024-10-03T12:28:57.428Z","updated_at":"2025-04-04T20:14:50.555Z","avatar_url":"https://github.com/jhawthorn.png","language":"Ruby","readme":"\u003e [!WARNING]  \n\u003e The recent work on performance and the [`JSON::Coder`](https://github.com/ruby/json#jsoncoder) interface in the standard `json` gem has made this library unnecessary 🎉. Please just use `json`!\n\n# RapidJSON\n\nFormerly Ruby's fastest JSON library! Built using the [RapidJSON C++ library](https://rapidjson.org/)\n\nActiveSupport integration, `json` gem emulation, and no monkey patches.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rapidjson'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install rapidjson\n\n## Usage\n\n``` ruby\nRapidJSON.parse \u003c\u003cJSON\n{\n  \"foo\":\"bar\"\n}\nJSON\n# =\u003e {\"foo\" =\u003e \"bar\"}\n```\n\n``` ruby\nRapidJSON.encode(json_string)\n# =\u003e '{\"foo\":\"bar\"}'\n```\n\n``` ruby\nRapidJSON.pretty_encode(json_string)\n# =\u003e\n# {\n#    \"foo\": \"bar\"\n# }\n```\n\nBy default the encoder is \"strict\" and will raise an exception.\n\n## ActiveSupport\n\nRapidJSON provides a drop-in replacement ActiveSupport encoder, with very good compatibility.\nAdd the following to an initializer to opt-in.\n\n```ruby\n# config/initializers/rapidjson.rb\n\nActiveSupport::JSON::Encoding.json_encoder = RapidJSON::ActiveSupportEncoder\n```\n\nThis makes `model.to_json` ~15x faster, and `nested_hash.to_json` ~27x faster (compared using Rails 7.0)\n\n## JSON gem compatibility\n\nContrary to some other JSON libraries, `RapidJSON` doesn't provide a monkey patch to entirely replace the stdlib JSON gem.\n\nHowever it does provide a module that behave like the stdlib JSON gem and that can be used to monkey patch existing code.\n\n```ruby\nmodule SomeLibrary\n  def do_stuff(payload)\n    JSON.parse(payload)\n  end\nend\n```\n\n```ruby\nSomeLibrary::JSON = RapidJSON::JSONGem\n```\n\nNote that this module only use `RapidJSON` when it's certain it is safe to do so. If the JSON gem is called with\nsome options that `RapidJSON` doesn't support, it automatically fallbacks to calling the JSON gem.\n\n## Advanced usage\n\nBy default RapidJSON will only encode \"JSON-ready\" types: `Hash`, `Array`, `Integer`, `Float`, `String`, `Symbol`, `true`, `false`, and `nil`.\n\nRapidJSON::Coder can be initialized with a block which allows the behaviour to be customized. This is how the ActiveSupport encoder and JSON compatibility above are implemented! Just using Ruby :heart:.\n\n```ruby\nRapidJSON::Coder.new do |object, is_key|\n  object.to_s # Convert any unknown object to string\nend\n```\n\nThe block is called only for unrecognized types. The return value is expected to be a \"JSON ready\" type which will then be encoded.\n\nOne additional special type is `RapidJSON::Fragment`, which is interpreted as an existing JSON-encoded string. This can be used to efficiently embed an existing JSON document, or to provide compatibility.\n\n## Performance\n\nYour current JSON parser/encoder is probably fine.\n\nUnless there's good reason, it's probably best sticking with the standard `json` gem, which ships with Ruby. It become much faster in version 2.3, so try it again if you haven't recently!\n\nHowever this library has a few performance advantages:\n\n* JSON parsing\n  * Performance is achieved mostly through using RapidJSON one of the fastest open source JSON parsing libraries. It supports SIMD (SSE2, SSE4.2, NEON), avoids allocated memory, and has been honed to be if not the fastest library (that honour likely going to simdjson), the library to beat for JSON performance.\n* Object allocation\n  * Wherever possible we avoid allocating objects. When generating JSON, RapidJSON will write the emitted JSON directly into the buffer of a Ruby string. (This is an optimization most Ruby JSON libraries will have)\n  * When parsing JSON we parse directly form the source string with a single copy\n  * When building a Hash for a JSON object, we use `fstrings` (dedup'd and frozen strings) as the key\n  * Whenever possible we build Ruby objects from C types (int, char \\*, double) rather than constructing intermediate Ruby string objects.\n\nMany of these optimization can be found in all popular Ruby JSON libraries\n\n```\n== Encoding canada.json (2090234 bytes)\n                yajl     13.957  (± 0.0%) i/s -     70.000  in   5.015358s\n                json     13.912  (± 0.0%) i/s -     70.000  in   5.032247s\n                  oj     20.821  (± 0.0%) i/s -    106.000  in   5.090981s\n           rapidjson     84.110  (± 2.4%) i/s -    424.000  in   5.042792s\n```\n\n```\n== Parsing canada.json (2251051 bytes)\n                yajl     35.510  (± 2.8%) i/s -    180.000  in   5.070803s\n                json     22.105  (± 0.0%) i/s -    112.000  in   5.067063s\n                  oj     15.163  (± 6.6%) i/s -     76.000  in   5.042864s\n           rapidjson    148.263  (± 2.0%) i/s -    742.000  in   5.006370s\n```\nNotes: oj seems unusually bad at this test, and is usually faster than yajl and\njson, and comparable to rapidjson.\n\nOther libraries may include modes to avoid constructing all objects. Currently\nRapidJSON only focuses on the patterns and APIs users are likely to actually\nuse.\n\n## Why another JSON library\n\nI spent a week working on YAJL/yajl-ruby, and though I really liked the library, it hasn't kept up with the performance of the modern JSON libraries, specifically simdjson (C++), serde-json (Rust), and RapidJSON (C++). I was interested in how those libraries would integrate into Ruby. Of these, RapidJSON was the simplest fit for a Ruby extension. It's in C++ (clean Rust/Ruby bindings is unfortunately a work in progress), fast, uses SIMD instructions, supports encoding and decoding, and has a nice API to work with.\n\nHowever, if you're happy with your current Ruby JSON library (including `json`) you should keep using it. They're all very good.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/jhawthorn/rapidjson. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/jhawthorn/rapidjson/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the RapidJSON project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/jhawthorn/rapidjson/blob/main/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhawthorn%2Frapidjson-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhawthorn%2Frapidjson-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhawthorn%2Frapidjson-ruby/lists"}