• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

FIXTURES/H20-Jan-2017-244231

Godeps/H20-Jan-2017-178174

formatter/H20-Jan-2017-750648

jd/H20-Jan-2017-10078

jp/H20-Jan-2017-6848

tests/H20-Jan-2017-3530

vendor/H20-Jan-2017-116,74998,400

.gitignoreH A D20-Jan-20176 11

LICENSEH A D20-Jan-20176.7 KiB146108

MakefileH A D20-Jan-2017150 64

README.mdH A D20-Jan-20172.4 KiB158129

deltas.goH A D20-Jan-201710.6 KiB462330

gojsondiff.goH A D20-Jan-201710.3 KiB427348

gojsondiff_suite_test.goH A D20-Jan-2017203 1410

gojsondiff_test.goH A D20-Jan-20173.6 KiB141114

unmarshaler.goH A D20-Jan-20172.9 KiB132116

unmarshaler_test.goH A D20-Jan-20171.8 KiB117111

wercker.ymlH A D20-Jan-2017176 1210

README.md

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
16go get github.com/yudai/gojsondiff
17```
18
19### Comparing two JSON strings
20
21See `jd/main.go` for how to use this library.
22
23
24## CLI tool
25
26This repository contains a package that you can use as a CLI tool.
27
28### Installation
29
30```sh
31go get github.com/yudai/gojsondiff/jd
32```
33
34### Usage
35
36#### Diff
37
38Just give two json files to the `jd` command:
39
40```sh
41jd one.json another.json
42```
43
44Outputs 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
88When you prefer the delta foramt of [jsondiffpatch](https://github.com/benjamine/jsondiffpatch), add the `-f delta` option.
89
90```sh
91jd -f delta one.json another.json
92```
93
94This 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
148Give a diff file in the delta format and the JSON file to the `jp` command.
149
150```sh
151jp diff.delta one.json
152```
153
154
155## License
156
157MIT License (see `LICENSE` for detail)
158