1jc(1)                            JSON Convert                            jc(1)
2
3
4

NAME

6       jc - JSON Convert JSONifies the output of many CLI tools and file-types
7

SYNOPSIS

9       COMMAND | jc PARSER [OPTIONS]
10
11       or "Magic" syntax:
12
13       jc [OPTIONS] COMMAND
14
15

DESCRIPTION

17       jc  JSONifies  the  output  of many CLI tools and file-types for easier
18       parsing in scripts. jc accepts piped input from  STDIN  and  outputs  a
19       JSON  representation of the previous command's output to STDOUT. Alter‐
20       natively, the "Magic" syntax can be used by prepending jc to  the  com‐
21       mand  to  be  converted. Options can be passed to jc immediately before
22       the command is given. (Note: "Magic"  syntax  does  not  support  shell
23       builtins or command aliases)
24
25

OPTIONS

27       Parsers:
28
29
30
31              --acpi `acpi` command parser
32
33
34              --airport
35                     `airport -I` command parser
36
37
38              --airport-s
39                     `airport -s` command parser
40
41
42              --arp  `arp` command parser
43
44
45              --asciitable
46                     ASCII and Unicode table parser
47
48
49              --asciitable-m
50                     multi-line ASCII and Unicode table parser
51
52
53              --blkid
54                     `blkid` command parser
55
56
57              --chage
58                     `chage --list` command parser
59
60
61              --cksum
62                     `cksum` and `sum` command parser
63
64
65              --crontab
66                     `crontab` command and file parser
67
68
69              --crontab-u
70                     `crontab` file parser with user support
71
72
73              --csv  CSV file parser
74
75
76              --csv-s
77                     CSV file streaming parser
78
79
80              --date `date` command parser
81
82
83              --df   `df` command parser
84
85
86              --dig  `dig` command parser
87
88
89              --dir  `dir` command parser
90
91
92              --dmidecode
93                     `dmidecode` command parser
94
95
96              --dpkg-l
97                     `dpkg -l` command parser
98
99
100              --du   `du` command parser
101
102
103              --env  `env` command parser
104
105
106              --file `file` command parser
107
108
109              --finger
110                     `finger` command parser
111
112
113              --free `free` command parser
114
115
116              --fstab
117                     `/etc/fstab` file parser
118
119
120              --git-log
121                     `git log` command parser
122
123
124              --git-log-s
125                     `git log` command streaming parser
126
127
128              --gpg  `gpg --with-colons` command parser
129
130
131              --group
132                     `/etc/group` file parser
133
134
135              --gshadow
136                     `/etc/gshadow` file parser
137
138
139              --hash `hash` command parser
140
141
142              --hashsum
143                     hashsum command parser (`md5sum`, `shasum`, etc.)
144
145
146              --hciconfig
147                     `hciconfig` command parser
148
149
150              --history
151                     `history` command parser
152
153
154              --hosts
155                     `/etc/hosts` file parser
156
157
158              --id   `id` command parser
159
160
161              --ifconfig
162                     `ifconfig` command parser
163
164
165              --ini  INI file parser
166
167
168              --iostat
169                     `iostat` command parser
170
171
172              --iostat-s
173                     `iostat` command streaming parser
174
175
176              --iptables
177                     `iptables` command parser
178
179
180              --iw-scan
181                     `iw dev [device] scan` command parser
182
183
184              --jar-manifest
185                     MANIFEST.MF file parser
186
187
188              --jobs `jobs` command parser
189
190
191              --kv   Key/Value file parser
192
193
194              --last `last` and `lastb` command parser
195
196
197              --ls   `ls` command parser
198
199
200              --ls-s `ls` command streaming parser
201
202
203              --lsblk
204                     `lsblk` command parser
205
206
207              --lsmod
208                     `lsmod` command parser
209
210
211              --lsof `lsof` command parser
212
213
214              --lsusb
215                     `lsusb` command parser
216
217
218              --mount
219                     `mount` command parser
220
221
222              --mpstat
223                     `mpstat` command parser
224
225
226              --mpstat-s
227                     `mpstat` command streaming parser
228
229
230              --netstat
231                     `netstat` command parser
232
233
234              --nmcli
235                     `nmcli` command parser
236
237
238              --ntpq `ntpq -p` command parser
239
240
241              --passwd
242                     `/etc/passwd` file parser
243
244
245              --pidstat
246                     `pidstat -h` command parser
247
248
249              --pidstat-s
250                     `pidstat -h` command streaming parser
251
252
253              --ping `ping` and `ping6` command parser
254
255
256              --ping-s
257                     `ping` and `ping6` command streaming parser
258
259
260              --pip-list
261                     `pip list` command parser
262
263
264              --pip-show
265                     `pip show` command parser
266
267
268              --postconf
269                     `postconf -M` command parser
270
271
272              --ps   `ps` command parser
273
274
275              --route
276                     `route` command parser
277
278
279              --rpm-qi
280                     `rpm -qi` command parser
281
282
283              --rsync
284                     `rsync` command parser
285
286
287              --rsync-s
288                     `rsync` command streaming parser
289
290
291              --sfdisk
292                     `sfdisk` command parser
293
294
295              --shadow
296                     `/etc/shadow` file parser
297
298
299              --ss   `ss` command parser
300
301
302              --stat `stat` command parser
303
304
305              --stat-s
306                     `stat` command streaming parser
307
308
309              --sysctl
310                     `sysctl` command parser
311
312
313              --systemctl
314                     `systemctl` command parser
315
316
317              --systemctl-lj
318                     `systemctl list-jobs` command parser
319
320
321              --systemctl-ls
322                     `systemctl list-sockets` command parser
323
324
325              --systemctl-luf
326                     `systemctl list-unit-files` command parser
327
328
329              --systeminfo
330                     `systeminfo` command parser
331
332
333              --time `/usr/bin/time` command parser
334
335
336              --timedatectl
337                     `timedatectl status` command parser
338
339
340              --top  `top -b` command parser
341
342
343              --top-s
344                     `top -b` command streaming parser
345
346
347              --tracepath
348                     `tracepath` and `tracepath6` command parser
349
350
351              --traceroute
352                     `traceroute` and `traceroute6` command parser
353
354
355              --ufw  `ufw status` command parser
356
357
358              --ufw-appinfo
359                     `ufw app info [application]` command parser
360
361
362              --uname
363                     `uname -a` command parser
364
365
366              --update-alt-gs
367                     `update-alternatives --get-selections` command parser
368
369
370              --update-alt-q
371                     `update-alternatives --query` command parser
372
373
374              --upower
375                     `upower` command parser
376
377
378              --uptime
379                     `uptime` command parser
380
381
382              --vmstat
383                     `vmstat` command parser
384
385
386              --vmstat-s
387                     `vmstat` command streaming parser
388
389
390              --w    `w` command parser
391
392
393              --wc   `wc` command parser
394
395
396              --who  `who` command parser
397
398
399              --x509-cert
400                     X.509 PEM and DER certificate file parser
401
402
403              --xml  XML file parser
404
405
406              --xrandr
407                     `xrandr` command parser
408
409
410              --yaml YAML file parser
411
412
413              --zipinfo
414                     `zipinfo` command parser
415
416
417
418       Options:
419
420
421              -a, --about
422                     About jc (JSON or YAML output)
423
424              -C, --force-color
425                     Force  color  output  even when using pipes (overrides -m
426                     and the NO_COLOR env variable)
427
428              -d, --debug
429                     Debug - show traceback (use -dd for verbose traceback)
430
431              -h, --help
432                     Help (--help --parser_name for parser documentation)
433
434              -m, --monochrome
435                     Monochrome output
436
437              -p, --pretty
438                     Pretty print output
439
440              -q, --quiet
441                     Quiet mode. Suppresses parser warning messages  (use  -qq
442                     to ignore streaming parser errors)
443
444              -r, --raw
445                     Raw  output. Provides more literal output, typically with
446                     string values and no additional semantic processing
447
448              -u, --unbuffer
449                     Unbuffer output (useful  for  slow  streaming  data  with
450                     streaming parsers)
451
452              -v, --version
453                     Version information
454
455              -y, --yaml-out
456                     YAML output
457
458              -B, --bash-comp
459                     Generate Bash shell completion script
460
461              -Z, --zsh-comp
462                     Generate Zsh shell completion script
463
464

EXIT CODES

466       Any fatal errors within jc will generate an exit code of 100, otherwise
467       the exit code will be 0. When using the "Magic" syntax (e.g. jc  ifcon‐
468       fig  eth0), jc will store the exit code of the program being parsed and
469       add it to the jc exit code. This way it is easier to  determine  if  an
470       error was from the parsed program or jc.
471
472       Consider the following examples using ifconfig:
473
474              ifconfig exit code = 0, jc exit code = 0, combined exit code = 0
475              (no errors)
476
477              ifconfig exit code = 1, jc exit code = 0, combined exit code = 1
478              (error in ifconfig)
479
480              ifconfig exit code = 0, jc exit code = 100, combined exit code =
481              100 (error in jc)
482
483              ifconfig exit code = 1, jc exit code = 100, combined exit code =
484              101 (error in both ifconfig and jc)
485
486

ENVIRONMENT

488       Custom Colors
489
490       You  can  specify custom colors via the JC_COLORS environment variable.
491       The JC_COLORS environment variable takes four  comma  separated  string
492       values in the following format:
493
494       JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
495
496       Where colors are: black, red, green, yellow, blue, magenta, cyan, gray,
497       brightblack, brightred, brightgreen, brightyellow, brightblue,  bright‐
498       magenta, brightcyan, white, or default
499
500       For example, to set to the default colors:
501
502              JC_COLORS=blue,brightblack,magenta,green
503
504              or
505
506              JC_COLORS=default,default,default,default
507
508       Disable Color Output
509
510       You  can  set the NO_COLOR environment variable to any value to disable
511       color output in jc. Note that using the -C option to force color output
512       will override both the NO_COLOR environment variable and the -m option.
513
514

STREAMING PARSERS

516       Most parsers load all of the data from STDIN, parse it, then output the
517       entire JSON document serially. There are some streaming  parsers  (e.g.
518       ls-s, ping-s, etc.) that immediately start processing and outputing the
519       data line-by-line as JSON Lines (aka NDJSON) while it is being received
520       from STDIN. This can significantly reduce the amount of memory required
521       to parse large amounts of command output (e.g. ls -lR /) and can  some‐
522       times  process  the  data more quickly. Streaming parsers have slightly
523       different behavior than standard parsers as outlined below.
524
525              Note: Streaming parsers cannot be used with the "magic" syntax
526
527       Ignoring Errors
528
529       You may want to ignore parsing  errors  when  using  streaming  parsers
530       since  these  may be used in long-lived processing pipelines and errors
531       can break the pipe. To ignore parsing errors, use the -qq  cli  option.
532       This  will  add a _jc_meta object to the JSON output with a success at‐
533       tribute. If success is true, then there  were  no  issues  parsing  the
534       line. If success is false, then a parsing issue was found and error and
535       line fields will be added to include a short error description and  the
536       contents of the unparsable line, respectively:
537
538              Successfully parsed line with -qq option:
539                     {
540                       "command_data": "data",
541                       "_jc_meta": {
542                         "success": true
543                       }
544                     }
545
546              Unsuccessfully parsed line with -qq option:
547                     {
548                       "_jc_meta": {
549                         "success": false,
550                         "error": "error message",
551                         "line": "original line data"
552                       }
553                     }
554
555       Unbuffering Output
556
557       Most  operating  systems  will  buffer  output that is being piped from
558       process to process. The buffer is usually around 4KB. When viewing  the
559       output  in the terminal the OS buffer is not engaged so output is imme‐
560       diately displayed on the screen. When  piping  multiple  processes  to‐
561       gether,  though, it may seem as if the output is hanging when the input
562       data is very slow (e.g. ping):
563
564              $ ping 1.1.1.1 | jc --ping-s | jq
565              <slow output>
566
567       This is because the OS engages the 4KB buffer between jc and jq in this
568       example.  To display the data on the terminal in realtime, you can dis‐
569       able the buffer with the -u (unbuffer) cli option:
570
571              $ ping 1.1.1.1 | jc --ping-s -u | jq
572              {"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...}
573              {"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...}
574              etc...
575
576              Note: Unbuffered output can be slower for large data streams.
577
578

CUSTOM PARSERS

580       Custom local parser plugins may be placed in a jc/jcparsers  folder  in
581       your local "App data directory":
582
583              - Linux/unix: $HOME/.local/share/jc/jcparsers
584              - macOS: $HOME/Library/Application Support/jc/jcparsers
585              - Windows: $LOCALAPPDATA\jc\jc\jcparsers
586
587       Local  parser  plugins  are  standard  python  module  files.  Use  the
588       jc/parsers/foo.py or jc/parsers/foo_s.py (streaming) parser as  a  tem‐
589       plate and simply place a .py file in the jcparsers subfolder.
590
591       Local  plugin filenames must be valid python module names and therefore
592       must start with a letter and consist entirely of alphanumerics and  un‐
593       derscores. Local plugins may override default parsers.
594
595       Note:  The  application  data  directory follows the XDG Base Directory
596       Specification
597
598

CAVEATS

600       Locale
601
602       For best results set the LANG  locale  environment  variable  to  C  or
603       en_US.UTF-8.  For  example,  either by setting directly on the command-
604       line:
605
606              $ LANG=C date | jc --date
607
608       or by exporting to the environment before running commands:
609
610              $ export LANG=C
611
612       On some older systems UTF-8 output will be downgraded to ASCII with  \u
613       escape sequences if the C locale does not support UTF-8 encoding.
614
615       Timezones
616
617       Some  parsers  have calculated epoch timestamp fields added to the out‐
618       put. Unless a timestamp field name has a _utc suffix it  is  considered
619       naive.  (i.e.  based  on the local timezone of the system the jc parser
620       was run on).
621
622       If a UTC timezone can be detected in the text of  the  command  output,
623       the  timestamp will be timezone aware and have a _utc suffix on the key
624       name. (e.g. epoch_utc) No other timezones are supported for aware time‐
625       stamps.
626
627

EXAMPLES

629       Standard Syntax:
630              $ dig www.google.com | jc --dig -p
631
632       Magic Syntax:
633              $ jc -p dig www.google.com
634
635       For parser documentation:
636              $ jc -h --dig
637

AUTHOR

639       Kelly Brazil (kellyjonbrazil@gmail.com)
640
641       https://github.com/kellyjonbrazil/jc
642
643
645       Copyright (c) 2019-2022 Kelly Brazil
646
647       License:  MIT License
648
649
650
6511.20.2                            2022-07-05                             jc(1)
Impressum