json-merge-patch

Implementation of JSON Merge Patch RFC7396

JSON Merge Patch

Implementation of JSON Merge Patch RFC7396

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  json-merge-patch:
    github: caspiano/json-merge-patch
  1. 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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

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