json-merge-patch
JSON Merge Patch
Implementation of JSON Merge Patch RFC7396
Installation
- Add the dependency to your
shard.yml
:
dependencies:
json-merge-patch:
github: caspiano/json-merge-patch
- Run
shards install
Usage
Via Module
require "json-merge-patch"
a = JSON.parse %({"hi": 1, "bye": 1})
b = JSON.parse %({"hi": 2, "bye": 2})
# use the module scope
puts JSON::Any::MergePatch.merge(a, b).to_json # => {"hi": 2, "bye": 2}
puts JSON::Any::MergePatch.merge(b, a).to_json # => {"hi": 1, "bye": 1}
# or...
puts JSON::RFC7396.merge(a, b).to_json # => {"hi": 2, "bye": 2}
puts JSON::RFC7396.merge(b, a).to_json # => {"hi": 1, "bye": 1}
Via require "json-merge-patch/ext"
require "json-merge-patch/ext"
a = JSON.parse %({"hi": 1, "bye": 1})
b = JSON.parse %({"hi": 2, "bye": 2})
# The module methods are included in addition to instance methods on `JSON::Any`
puts a.merge(b) # => {"hi": 2, "bye": 2}
puts b.merge(a) # => {"hi": 1, "bye": 1}
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Caspian Baska - creator and maintainer
Repository
json-merge-patch
Owner
Statistic
- 1
- 0
- 0
- 1
- 0
- over 2 years ago
- June 11, 2022
License
MIT License
Links
Synced at
Sun, 24 Nov 2024 05:49:42 GMT
Languages