-
Notifications
You must be signed in to change notification settings - Fork 0
/
man.1
330 lines (255 loc) · 6.73 KB
/
man.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
.TH json_merger 1
.SH "NAME"
json_merger \- Merge JSON files based on indicators
.SH "SYNOPSIS"
json_merger [OPTION]... [file]...
.SH "DESCRIPTION"
json_merger is a way to merge JSON files based on indicators such as
\fB@extends\fR, \fB@match\fR, \fB@override\fR and \fB@delete\fR. Only works for
a \fBROOT NODE\fR
.SH "OPTIONS"
.IP "\fB-p\fR, \fB--pretty\fR" 4
Prettify, indent the output JSON in a human way.
.IP "\fB-s\fR, \fB--suffix\fR <\fI.suffix\fR>" 4
Output suffix. Suffix added to input files to construct output files. If left
blank then \fBstdout\fR is used.
.IP "\fB-v\fR, \fB--variable\fR <\fIkey=value\fR>" 4
Set \fBkey=value\fR variables. See "PATH TEMPLATING".
.IP "\fB-h\fR, \fB--help\fR" 4
Show help and exit.
.IP "\fB-V\fR, \fB--version\fR" 4
Print version information.
.SH "INDICATORS"
.IP "\fB@extends\fR" 4
An array or string of path names to files which should be extended.
.IP "\fB@override\fR" 4
An array, string or \fBtrue\fR indicating that the given property will be
overridden. \fBMATCH SYNTAX\fR is supported. See "@delete"
.IP "\fB@delete\fR" 4
An array, string or \fBtrue\fR indicating that the given property will be
deleted. When used with \fBtrue\fR the whole node will be overridden. When
used with an array only the listed properties will be overridden. \fBMATCH
SYNTAX\fR is supported.
\fB@delete\fR will always delete the listed nodes, while ignoring all regular
properties, while \fB@override\fR will empty the listed nodes, and merge ontop
of that, this will also leave an empty object.
.IP "\fB@append\fR, \fB@prepend\fR, \fB@insert\fR" 4
When working with arrays the default behaviour will be to merge on indexes, i.e.
first item in the arrays will be merged together.
Using \fB@append\fR one can force the node to be appended at the end of the
destination array.
Using \fB@prepend\fR one can force the node to be prepended at the beginning
of the destination array. Note that \fB@prepend\fR will insert at index 0, 1, 2
accordantly to make the JSON represent the sequence of which the nodes are
inserted.
Using \fB@insert\fR one can specify the index at which the node should be
inserted.
.IP "\fB@match\fR" 4
Match can be used to match a given item in an array. See "MATCH SYNTAX" for
more information.
.IP "\fB@move\fR" 4
This indicator is the same as \fB@insert\fR, but is used together with
\fB@match\fR.
.IP "\fB@value\fR" 4
Used together with the \fB@insert\fR family of indicators, to insert a primitive
value at a specific location. See "EXAMPLE" for an example.
.IP "\fB@comment\fR" 4
These will be removed in the final output file, and is intended to be used for
internal comments.
.IP "\fB@id\fR" 4
Global ID's that can be matched with \fB@match\fR.
.SH "PATH TEMPLATING"
Paths specified in \fB@extends\fR can be templated using the following syntax:
\fB$variable\fR and \fB${variable}\fR.
See the following example:
\& $ cat a.json
.br
\& { "@extends": ["${my_var}.json"], "a": 1 }
.br
\& $ cat b.json
.br
\& { "b": 1 }
.br
\& $ json_merger -v my_var=b a.json
.br
\& { "b": 1, "a": 1 }
.SH "MATCH SYNTAX"
.IP "\fBProperty\fR" 4
Match a property with a primitive value, the syntax is:
\& [property]
.br
\& [property=value]
.br
\& [property='value']
.br
\& [@SPECIAL=value]
If single quotes is used a string will be matches. Note that a string will
still be checked even when they are omitted.
Check for a property beginning, containing and ending with \fBvalue\fR
\& [property^=value]
.br
\& [property*=value]
.br
\& [property$=value]
The list of \fB@SPECIAL\fR are:
\fB@value\fR use to match primitives in arrays.
.br
\fB@id\fR use to match specified ID's. See "INDICATORS".
.IP "\fBID\fR" 4
Match an ID specified with \fB@id\fR. The syntax is:
\& #id
See "INDICATORS".
.IP "\fBDirectory\fR" 4
Match a property name and ascend into that matches node, the syntax is:
\& name/
.SH "EXAMPLE"
.IP "\fB@extends\fR" 4
To extend the files \fBc.json\fR and then \fBb.json\fR one could write:
\& {
.br
\& "@extends": ["b.json", "c.json"]
.br
\& }
This will take \fBb.json\fR as the base file. Then apply \fBc.json\fR on top.
And finally apply the initial file on top of that output.
If \fBb.json\fR or \fBc.json\fR contains \fR@extends\fR indicators these will be
resolved beforehand.
.IP "\fB@override\fR" 4
Having \fBb.json\fR as:
\& {
.br
\& "prop1": { "b": 1 }
.br
\& }
One can override \fBprop1\fR with:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "prop1": { "@override": true, "a": 1 }
.br
\& }
The same can be archived using:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "@override": ["prop1"],
.br
\& "prop1": { "a": 1 }
.br
\& }
.IP "\fB@insert\fR" 4
Having \fBb.json\fR as:
\& {
.br
\& "arr": ["A", "B", "C"]
.br
\& }
One can insert an object between \fBA\fR and \fBB\fR with:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "arr": [ { "@insert": 1, "a": 1 } ]
.br
\& }
The same applies for \fB@append\fR and \fB@prepend\fR.
If one wants to insert a primitive value, or an array, one can use
\fB@value\fR. Taking the example from above:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "arr": [ { "@insert": 1, "@value": "A2" }
.br
\& }
.IP "\fBMatch Property\fR" 4
Having \fBb.json\fR as:
\& {
.br
\& "arr": [
.br
\& { "a": 1 },
.br
\& { "a": 2 },
.br
\& { "a": 3 }
.br
\& }
One can match the second element \fB{ "a": 2 }\fR with:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "arr": [ { "@match": "[a=2]" } ]
.br
\& }
.IP "\fBMatch Directory\fR" 4
Having \fBb.json\fR as:
\& {
.br
\& "a": {
.br
\& "b": {
.br
\& "c": 1
.br
\& }
.br
\& }
.br
\& }
One can match the the path object containing \fBc = 1\fR with:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "@match": "a/b/[c=1]"
.br
\& }
.IP "\fBMatch @value\fR" 4
Having \fBb.json\fR as:
\& {
.br
\& "arr": [ "A", "B", "C" ]
.br
\& }
One can match and delete the \fBB\fR with:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "arr": [ { "@delete": true, "@match": "[@value=B]" } ]
.br
\& }
.IP "\fBMatch @id\fR" 4
Having \fBb.json\fR as:
\& {
.br
\& "a": { "@id": "a" },
.br
\& "b": { "@id": "b" }
.br
\& }
One can match and delete the \fBa\fR with:
\& {
.br
\& "@extends": ["b.json"],
.br
\& "@match": "#a",
.br
\& "@delete": true
.br
\& }
.SH "ROOT NODE"
A root node is the outer most node in a JSON file. These can contain
\fB@extends\fR, but \fIcannot\fR be deleted nor overridden.
.SH "EXIT STATUS"
The following exit values shall be returned:
.IP "\fB0\fR" 4
Successful completion.
.IP "\fB>0\fR" 4
An error occurred.
.SH "AUTHOR"
Andreas Louv <[email protected]> is the author of \fBjson_merger\fR.