Skip to content

Commit e8121d5

Browse files
committed
Updated readme
1 parent 6d99d65 commit e8121d5

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# JSON Merge Patch
2+
A `JSON Merge Patch` utility forked from [json-patch](https://github.com/evanphx/json-patch) and based on [fastjson](github.com/valyala/fastjson), with WASM/WASI support for [TinyGo](https://tinygo.org/).
3+
4+
## Wasm Support
5+
The TinyGo compiler doesn't support `encoding/json` or some of the `reflect` package that most JSON serializers are based on.
6+
7+
Luckily `valyala/fastjson` is a native go implementation that doesn't rely on `encoding/json` and only uses the supported `reflect` functions.
8+
9+
Therefore this package is a TinyGo compliant library for `JSON Merge Patch`.
10+
11+
## Usage
12+
Public Functions:
13+
- `MergePatch(doc, merge) -> doc` : Applies a MergePatch to a JSON document and returns the new doc.
14+
- `MergeMergePatch(merge, merge) -> merge` : Merges two Merge Patch documents into a single.
15+
16+
```
17+
package main
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/lens-vm/jsonmerge"
23+
)
24+
25+
func main() {
26+
// Let's create a merge patch and a original document...
27+
original := []byte(`{"name": "John", "age": 24, "height": 3.21}`)
28+
merge := []byte(`{"name": "Jane", "age": 21}`)
29+
30+
new, err := jsonpatch.MergePatch(original, merge)
31+
if err != nil {
32+
panic(err)
33+
}
34+
35+
fmt.Printf("new merged document: %s\n", new)
36+
// outputs {{"name": "Jane", "age": 21, "height": 3.21}}
37+
}
38+
```
39+
40+
## Roadmap
41+
Currently this project succesfully passes much of the [JSON Merge RFC Tests](https://tools.ietf.org/html/rfc7386) for applying merges to 1. Documents 2. Other Merges.
42+
43+
Next steps is to support creating a Merge from the diff of two existing JSON Docs. This is suppported in the orignal `evanphx/json-patch` library, but the changes haven't made its way here.
44+
45+
## IMPORTANT
46+
This library is an adaptation of / based on [evanphx/json-patch](https://github.com/evanphx/json-patch). The goal of this fork is to replace the original libraries dependancy on `encoding/json` with `valyala/fastjson`. The original license (BSD 3-Clause) is maintained, and the original copyright is maintained in the unchanged files.
47+
48+
## Contributors
49+
- John-Alan Simmons ([@jsimnz](https://github.com/jsimnz))
50+
- Evan Pheonix ([@evanphx](https://github.com/evanphx)) (Original Fork)

0 commit comments

Comments
 (0)