Skip to content

Commit

Permalink
expanded documentation for using Oj to replace JSON (#714)
Browse files Browse the repository at this point in the history
* expanded documentation for using Oj to replace JSON

* doc improvements wip
  • Loading branch information
jjb committed Oct 10, 2021
1 parent 48104a1 commit 1d219ea
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ or in Bundler:
gem 'oj'
```

## Rails and json quickstart

See the Quickstart sections of the [Rails](pages/Rails.md) and [json](pages/JsonGem.md) docs.

## multi_json

Code which uses [multi_json](https://github.com/intridea/multi_json)
will automatically prefer Oj if it is installed.

## Support

[Get supported Oj with a Tidelift Subscription.](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme) Security updates are [supported](https://tidelift.com/security).
Expand Down
15 changes: 15 additions & 0 deletions pages/JsonGem.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# JSON Quickstart

To have Oj universally "take over" many methods on the JSON constant (`load`, `parse`, etc.) with
their faster Oj counterparts, in a mode that is compatible with the json gem:

```ruby
Oj.mimic_JSON()
```

If the project does not already use the json gem, `JSON` will become available.
If the project does require the json gem, `Oj.mimic_JSON()` should be invoked after the
json gem has been required.

For more details and options, read on...

# Oj JSON Gem Compatibility

The `:compat` mode mimics the json gem. The json gem is built around the use
Expand Down
3 changes: 2 additions & 1 deletion pages/Modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ if a non-native type is encountered instead of raising an Exception.
The `:compat` mode mimics the json gem. The json gem is built around the use
of the `to_json(*)` method defined for a class. Oj attempts to provide the
same functionality by being a drop in replacement with a few
exceptions. [{file:JsonGem.md}](JsonGem.md) includes more details on
exceptions. To universally replace many `JSON` methods with their faster Oj counterparts,
simply run `Oj.mimic_json`. [{file:JsonGem.md}](JsonGem.md) includes more details on
compatibility and use.

## :rails Mode
Expand Down
12 changes: 12 additions & 0 deletions pages/Rails.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Rails Quickstart

To universally replace Rails' use of the json gem with Oj, and also
have Oj "take over" many methods on the JSON constant (`load`, `parse`, etc.) with
their faster Oj counterparts, add this to an initializer:

```ruby
Oj.optimize_rails()
```

For more details and options, read on...

# Oj Rails Compatibility

The `:rails` mode mimics the ActiveSupport version 5 encoder. Rails and
Expand Down

0 comments on commit 1d219ea

Please sign in to comment.