Skip to content

Commit 4d0a16e

Browse files
committed
Merge branch 'master' of github.com:j-tester/json-diff-cli
2 parents db788ed + a224be4 commit 4d0a16e

File tree

3 files changed

+4336
-20
lines changed

3 files changed

+4336
-20
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
json-diff-cli allows you to diff the JSON of two urls and see what the differences are. This tool can be used for testing purposes or to simply check that things are working.
44

55
# Usage
6+
67
```
78
Commands:
89
@@ -13,15 +14,19 @@ Commands:
1314
```
1415

1516
## DIFF
17+
1618
### diff the json between two urls and print to the console.
19+
1720
```
1821
jsondiff diff <leftURL> <rightURL> [options]
1922
```
23+
2024
**`leftURL`**: The base URL you would like to compare to.
2125

2226
**`rightURL`**: The new/updated URL. The JSON from `rightURL` will be compared with the `leftURL` and changes will be printed out to the console.
2327

2428
### Options
29+
2530
```
2631
Usage: diff [options] <leftURL> <rightURL>
2732
@@ -31,6 +36,7 @@ Options:
3136
3237
--help output usage information
3338
-o, --output <file> print the output to a CSV file
39+
-f, --failOnDiff return exit code 1 if there is a difference
3440
-x, --diffheaders diff the headers as well as the body
3541
-H, --headers <string> attach a header to the request. You may string multipe headers together by passing along more -H or --header options
3642
-i, --ignore <key> ignore the provided key. You may string multipe ignore keys together by passing along more -i or --ignore options
@@ -43,7 +49,9 @@ Options:
4349
### Example
4450

4551
#### Input
52+
4653
##### leftJSON
54+
4755
```json
4856
{
4957
"foo": {
@@ -54,7 +62,9 @@ Options:
5462
}
5563
}
5664
```
65+
5766
##### rightJSON
67+
5868
```json
5969
{
6070
"foo": {
@@ -67,6 +77,7 @@ Options:
6777
```
6878

6979
#### Output
80+
7081
```
7182
key left right diff
7283
--------- ------------ ------------ -------
@@ -76,6 +87,7 @@ foo.bar.a true false updated
7687
```
7788

7889
## CSV
90+
7991
### diff the json between urls in a csv file, print to the console, and output into a csv file.
8092

8193
```
@@ -85,6 +97,7 @@ jsondiff csv <input> [options]
8597
**`input`**: Path to the input file (CSV format).
8698

8799
### Options
100+
88101
```
89102
Usage: csv [options] <path>
90103
@@ -100,8 +113,11 @@ Options:
100113
```
101114

102115
### Example
116+
103117
#### Input
118+
104119
**The first line in the CSV file must have the following headers. You may chose to omit any of them except for `ur1`, and `url2`**
120+
105121
```
106122
url1, url2, method, headers, body, sortKey, ignore
107123
```
@@ -130,7 +146,9 @@ https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/
130146
```
131147

132148
#### Output
149+
133150
##### csv
151+
134152
```
135153
id,left url,left response time,right url,right response time,key,left value,right value,difference,status
136154
0,https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/a.json,1197,https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/b.json,675,foo.bar.c,undefined,now you dont,added,fail
@@ -143,7 +161,9 @@ id,left url,left response time,right url,right response time,key,left value,righ
143161
2,https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/a.json,396,https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/b.json,386,foo.bar.b,now u see me,undefined,deleted,fail
144162
2,https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/a.json,396,https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/b.json,386,foo.bar.a,true,none,updated,fail
145163
```
164+
146165
##### console
166+
147167
```
148168
https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/a.json vs https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/b.json
149169
key left right diff

index.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,35 @@ const csvScript = require('./scripts/csv');
77

88
yargs.usage('$0 <cmd> [args]');
99

10-
yargs
11-
.command('diff <leftURL> <rightURL> [options]', 'diffs the json response of two URLs.', {
10+
yargs.command(
11+
'diff <leftURL> <rightURL> [options]',
12+
'diffs the json response of two URLs.',
13+
{
1214
output: {
1315
alias: 'o',
1416
describe: 'print the output to a CSV file',
1517
type: 'string',
1618
},
19+
quiet: {
20+
alias: 'q',
21+
describe: 'silences the console output',
22+
type: 'boolean',
23+
default: false,
24+
},
25+
failOnDiff: {
26+
alias: 'f',
27+
default: false,
28+
describe: 'return exit code 1 if there is a difference',
29+
type: 'boolean',
30+
},
31+
expectedStatusCode: {
32+
describe: 'expected status codes of the requests',
33+
type: 'string',
34+
},
35+
customCompare: {
36+
describe: 'custom compare json as string',
37+
type: 'string',
38+
},
1739
method: {
1840
alias: 'm',
1941
default: 'GET',
@@ -49,7 +71,8 @@ yargs
4971
},
5072
headers: {
5173
alias: 'H',
52-
describe: 'attach a header to the request. separate multiple headers with a space: -H "Accept: text/plain" "Accept-Charset: utf-8"',
74+
describe:
75+
'attach a header to the request. separate multiple headers with a space: -H "Accept: text/plain" "Accept-Charset: utf-8"',
5376
type: 'array',
5477
},
5578
ignore: {
@@ -59,18 +82,23 @@ yargs
5982
},
6083
body: {
6184
alias: 'b',
62-
describe: 'request body (only for POST) separate multiple body parts with a space: -b "username: testing" "password: 123"',
85+
describe:
86+
'request body (only for POST) separate multiple body parts with a space: -b "username: testing" "password: 123"',
6387
type: 'array',
6488
},
6589
arraysortkey: {
6690
alias: 'a',
6791
describe: 'sort nested arrays by the sort key, defaults to id',
6892
type: 'string',
6993
},
70-
}, diffScript);
94+
},
95+
diffScript,
96+
);
7197

72-
yargs
73-
.command('csv <path> [options]', 'diffs all urls in a csv file', {
98+
yargs.command(
99+
'csv <path> [options]',
100+
'diffs all urls in a csv file',
101+
{
74102
output: {
75103
alias: 'o',
76104
describe: 'print the output to a CSV file',
@@ -94,7 +122,9 @@ yargs
94122
default: 5000,
95123
type: 'number',
96124
},
97-
}, csvScript);
125+
},
126+
csvScript,
127+
);
98128

99129
yargs.help();
100130

0 commit comments

Comments
 (0)