Skip to content

RFC 6901/6902 (Json Pointer & Patch) for Elixir

License

Notifications You must be signed in to change notification settings

lygaret/ex-jsonrfc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JsonRfc

CI Build Hex pm

Pure-elixir implementations of IETF RFCs 6901 and 6902, JSON Pointer and Patch respectively.

RFC 6901, Json Pointer

RFC 6901 - Json Pointer "defines a string syntax for identifying a specific value within a JavaScript Object Notation (JSON) document," which for our purposes are maps with string keys or arrays.

  iex> doc = %{"foo" => %{"bar" => "baz", "xyzzy" => ["a", "b", "c"]}}

  iex> JsonRfc.Pointer.fetch(doc, "/foo/bar")
  {:ok, "baz"}

  iex> JsonRfc.Pointer.fetch(doc, "/foo/xyzzy/1")
  {:ok, "b"}

RFC 6902, Json Patch

RFC 6902 - Json Patch "defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation (JSON) document."

This is represented here by a "operation maps" and a reducer over maps with string keys and arrays.

  iex> doc = %{"foo" => [], "byebye" => 5}
  iex> ops = [
  ...>   JsonRfc.Patch.add("/bar", 3),
  ...>   JsonRfc.Patch.replace("/foo", %{}),
  ...>   JsonRfc.Patch.remove("/byebye"),
  ...>   JsonRfc.Patch.move("/bar", "/foo/bar"),
  ...>   JsonRfc.Patch.copy("/foo", "/baz")
  ...> ]

  iex> JsonRfc.Patch.evaluate(doc, ops)
  {:ok, %{"foo" => %{"bar" => 3}, "baz" => %{"bar" => 3}}}

Installation

def deps do
  [
    {:jsonrfc, "~> 0.1.0"}
  ]
end

About

RFC 6901/6902 (Json Pointer & Patch) for Elixir

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages