corka149
Jsonpatch - Pure Elixir implementation of RFC 6902
A JSON patch is a way to define a sequence of manipulating operations on a JavaScript object. The IETF published the RFC 6902 - found here RFC 6902 - JavaScript Object Notation (JSON) Patch. The Kubernetes API is an user of those JSON patches. In my opinion this is the easiest way to change a Kubernetes resource. Unfortunantely no library was available until yet or I did not fount it. This was my motivation to create the JSON patch library.
- Get Jsonpatch here jsonpatch | Hex
- Read the documentation here Jsonpatch — Jsonpatch v2.3.1
- And source GitHub - corka149/jsonpatch: A implementation of RFC 6902 in pure Elixir.
In this sense - keep calm and code Elixir
Your Corka/Sebastian
Most Liked
corka149
v1.0.0
I know it exists but never had the time to implement it. I am talking about that patching of lists at top level never worked. This was for me the milestone for v1.0.0. Finally it is fixed.
.
Changes:
- Allow lists at top level of Jsonpatch.apply_patch
- Fix error message when updating a non existing key in list
- Performance boost for diffing
Example of new feature:
iex(1)> source = [1, 2, 3, 5, 6]
[1, 2, 3, 5, 6]
iex(2)> destination = [1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
iex(3)> patch = Jsonpatch.diff source, destination
[
%Jsonpatch.Operation.Add{path: "/5", value: 6},
%Jsonpatch.Operation.Replace{path: "/4", value: 5},
%Jsonpatch.Operation.Replace{path: "/3", value: 4}
]
iex(4)> Jsonpatch.apply_patch! patch, source
[1, 2, 3, 4, 5, 6]
corka149
v0.9.3
It has been a since the last update. I worked on testing to eliminate dead code and bugs (of course). Also I tried to make the documentation a little bit prettier.
- Jsonpatch — Jsonpatch v0.9.3 |> read_documentation
- jsonpatch | Hex |> get_dependency
- GitHub - corka149/jsonpatch: A implementation of RFC 6902 in pure Elixir. |> browse_code
I am happy about any feedback.
Your Corka/Sebastian
corka149
v0.11.0
The whole process for creating patches through Jsonpatch.diff/2 was not perfect. I was encouraged through a github issue to rewrite it with a reduce-loop. This version fixes this. In addition, Jsonpatch.FlatMap was removed because it is not necessary anymore and it was not the focus of this lib.
Changelog:
- Removed module Jsonpatch.FlatMap because it is not necessary anymore and not the focus of the lib
- Reworked creating diff to create less unnecessary data and for more accurate patches
- Fixed adding values to empty lists (thanks @webdeb )
Updated documentation: Jsonpatch — Jsonpatch v0.11.0
corka149
v1.0.1
This version fixes a small bug while creating diffs.
Changes:
- Escape remaining keys before comparing them to the (already escaped) keys from earlier in the diffing process when determining Remove operations
Kudos to @ACBullen for detecting and fixing it. ![]()
Go this way for the new version
jsonpatch | Hex
corka149
v2.2.0
Yet another improvement.
The new version solves some edge cases regarding patching the root document by providing "" as path. In addition thx to @tulinmola a new option was added that allows to ignore invalid paths.
iex> # Patch will succeed, not applying invalid path operations.
iex> patch = [
...> %{op: "replace", path: "/name", value: "Alice"},
...> %{op: "replace", path: "/age", value: 42}
...> ]
iex> target = %{"name" => "Bob"} # No age in target
iex> Jsonpatch.apply_patch(patch, target, ignore_invalid_paths: true)
{:ok, %{"name" => "Alice"}}







