corka149

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.

In this sense - keep calm and code Elixir
Your Corka/Sebastian

First Post!

olafura

olafura

There was:

But it doesn’t seem to have been updated in a while according to hex. Also when I used that library at my last company I noticed it wasn’t that fast. So there is defiantly room for improvement.

I’m not sure it’s good to rely on a json encoder/decoder.

Also be careful about lists they are not that clear in json patch standard and can cause of lot of problems.

Most Liked

corka149

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. :partying_face:.

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

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.

I am happy about any feedback.

Your Corka/Sebastian

corka149

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

Last Post!

corka149

corka149

v2.3.0

New features, improvements and a bugfix. Thanks to @Valian, who did all the work!

Changelog

  • Feature - Customize diffs for structs (prepare maps or structs before diffing)
  • Feature - Add an option to set initial path
  • Bugfix - Incorrect apply_patch for the move operation for the same list
  • Improvements - Dedicated functions for map and list diffs

Checkout the README for more details

Where Next?

Popular in Announcing Top

Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_orde...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement