Debian Codegraph @

README.md

raw
1 # Go JSON Diff (and Patch)
2
3 [![Wercker](https://app.wercker.com/status/00d70daaf40ce277fd4f10290f097b9d/s/master)][wercker]
4 [![GoDoc](https://godoc.org/github.com/yudai/gojsondiff?status.svg)][godoc]
5 [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg)][license]
6
7 [wercker]: https://app.wercker.com/project/bykey/00d70daaf40ce277fd4f10290f097b9d
8 [godoc]: https://godoc.org/github.com/yudai/gojsondiff
9 [license]: https://github.com/yudai/gojsondiff/blob/master/LICENSE
10
11 ## How to use
12
13 ### Installation
14
15 ```sh
16 go get github.com/yudai/gojsondiff
17 ```
18
19 ### Comparing two JSON strings
20
21 See `jd/main.go` for how to use this library.
22
23
24 ## CLI tool
25
26 This repository contains a package that you can use as a CLI tool.
27
28 ### Installation
29
30 ```sh
31 go get github.com/yudai/gojsondiff/jd
32 ```
33
34 ### Usage
35
36 #### Diff
37
38 Just give two json files to the `jd` command:
39
40 ```sh
41 jd one.json another.json
42 ```
43
44 Outputs would be something like:
45
46 ```diff
47 {
48 "arr": [
49 0: "arr0",
50 1: 21,
51 2: {
52 "num": 1,
53 - "str": "pek3f"
54 + "str": "changed"
55 },
56 3: [
57 0: 0,
58 - 1: "1"
59 + 1: "changed"
60 ]
61 ],
62 "bool": true,
63 "num_float": 39.39,
64 "num_int": 13,
65 "obj": {
66 "arr": [
67 0: 17,
68 1: "str",
69 2: {
70 - "str": "eafeb"
71 + "str": "changed"
72 }
73 ],
74 + "new": "added",
75 - "num": 19,
76 "obj": {
77 - "num": 14,
78 + "num": 9999
79 - "str": "efj3"
80 + "str": "changed"
81 },
82 "str": "bcded"
83 },
84 "str": "abcde"
85 }
86 ```
87
88 When you prefer the delta format of [jsondiffpatch](https://github.com/benjamine/jsondiffpatch), add the `-f delta` option.
89
90 ```sh
91 jd -f delta one.json another.json
92 ```
93
94 This command shows:
95
96 ```json
97 {
98 "arr": {
99 "2": {
100 "str": [
101 "pek3f",
102 "changed"
103 ]
104 },
105 "3": {
106 "1": [
107 "1",
108 "changed"
109 ],
110 "_t": "a"
111 },
112 "_t": "a"
113 },
114 "obj": {
115 "arr": {
116 "2": {
117 "str": [
118 "eafeb",
119 "changed"
120 ]
121 },
122 "_t": "a"
123 },
124 "new": [
125 "added"
126 ],
127 "num": [
128 19,
129 0,
130 0
131 ],
132 "obj": {
133 "num": [
134 14,
135 9999
136 ],
137 "str": [
138 "efj3",
139 "changed"
140 ]
141 }
142 }
143 }
144 ```
145
146 #### Patch
147
148 Give a diff file in the delta format and the JSON file to the `jp` command.
149
150 ```sh
151 jp diff.delta one.json
152 ```
153
154
155 ## License
156
157 MIT License (see `LICENSE` for detail)