1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-03 17:44:07 +02:00

Compare commits

...

224 Commits

Author SHA1 Message Date
Kelly Brazil
727fc9a701 doc update 2022-03-05 15:19:25 -08:00
Kelly Brazil
306512d6bb force AM/PM to uppercase in date parser 2022-03-05 15:13:47 -08:00
Kelly Brazil
6afb1d389c Merge pull request #209 from kellyjonbrazil/dev
Dev v1.18.4
2022-03-05 21:49:36 +00:00
Kelly Brazil
9861983481 doc update 2022-03-05 13:45:28 -08:00
Kelly Brazil
ca79053db0 document pydoc version 2022-03-05 12:15:47 -08:00
Kelly Brazil
29c263f878 pydoc formatting fixes 2022-03-05 12:15:14 -08:00
Kelly Brazil
128c3c170a doc update 2022-03-04 16:38:49 -08:00
Kelly Brazil
a531ab8864 formatting 2022-03-04 16:35:06 -08:00
Kelly Brazil
0c1be7cc11 reduce dig example size 2022-03-04 16:29:36 -08:00
Kelly Brazil
e4222b45f5 fix names to mod names 2022-03-04 16:24:13 -08:00
Kelly Brazil
ac32c69c31 formatting 2022-03-04 13:35:16 -08:00
Kelly Brazil
cb2dfeac8d change name to JSON Convert 2022-03-04 13:27:39 -08:00
Kelly Brazil
9a3602e70b doc update 2022-03-04 08:57:11 -08:00
Kelly Brazil
a9f53ee258 optimize streaming parser detection in cli 2022-03-03 17:50:19 -08:00
Kelly Brazil
6be3d3d982 doc update 2022-03-03 17:38:47 -08:00
Kelly Brazil
e49df72083 use streaming parser list to find streaming parsers 2022-03-03 17:37:01 -08:00
Kelly Brazil
7ede7be7bf add standard and streaming list functions 2022-03-03 17:36:40 -08:00
Kelly Brazil
4758e28a36 formatting 2022-03-02 15:24:18 -08:00
Kelly Brazil
4a1ee151b3 add dhcp6 options to docs 2022-03-02 10:57:09 -08:00
Kelly Brazil
8c8afc1a92 formatting 2022-03-02 10:15:01 -08:00
Kelly Brazil
ed205f7720 doc update 2022-02-28 12:55:05 -08:00
Kelly Brazil
d65f7ae992 add nmcli 2022-02-28 12:26:06 -08:00
Kelly Brazil
e2ffef57b9 fix test 2022-02-28 12:20:39 -08:00
Kelly Brazil
002caa9fb3 add fedora tests 2022-02-28 12:19:02 -08:00
Kelly Brazil
b7c6faf3da enhance error message 2022-02-25 11:23:20 -08:00
Kelly Brazil
554ca61d17 add tests 2022-02-25 11:19:20 -08:00
Kelly Brazil
7b9722d255 fix formatting 2022-02-24 21:21:02 -08:00
Kelly Brazil
5505bde8ef doc update 2022-02-24 20:53:54 -08:00
Kelly Brazil
dbcd9a4060 bump version to 1.0 2022-02-24 20:52:28 -08:00
Kelly Brazil
4bdeb2b3aa simplify warning message 2022-02-24 20:52:18 -08:00
Kelly Brazil
6ae1d03187 doc fix 2022-02-24 20:47:15 -08:00
Kelly Brazil
f75b06abe4 doc update 2022-02-24 20:43:20 -08:00
Kelly Brazil
1923925710 update changelog 2022-02-24 20:35:00 -08:00
Kelly Brazil
2c5c57ae04 version bump 2022-02-24 20:33:10 -08:00
Kelly Brazil
f4d11d697e finish use cases and doc 2022-02-24 20:31:58 -08:00
Kelly Brazil
7f409b7082 enhance ParseError cli message 2022-02-24 20:31:09 -08:00
Kelly Brazil
937fa5aad2 split dhcp options 2022-02-24 18:22:19 -08:00
Kelly Brazil
19dcef5135 firm up flow. add/remove text. parse routes 2022-02-24 17:10:39 -08:00
Kelly Brazil
3d01356461 add text_kv function 2022-02-24 14:53:26 -08:00
Kelly Brazil
2d6f666fa4 add dev show and conn show parsers 2022-02-24 12:21:13 -08:00
Kelly Brazil
4dda895f12 initial nmcli parser 2022-02-24 11:25:14 -08:00
Kelly Brazil
52617b1722 Merge pull request #208 from kellyjonbrazil/master
sync to dev
2022-02-21 16:35:12 +00:00
Kelly Brazil
961968a0fc fix schema 2022-02-14 15:14:22 -08:00
Kelly Brazil
f026a788e5 add xrandr example 2022-02-14 11:30:03 -08:00
Kelly Brazil
2f7c03eb35 Merge pull request #207 from kellyjonbrazil/dev
Dev v1.18.3
2022-02-14 10:36:08 -08:00
Kelly Brazil
3afaa48eee doc update 2022-02-14 10:31:41 -08:00
Kelly Brazil
3201452564 add -p to example 2022-02-14 10:06:09 -08:00
Kelly Brazil
7ee1e34fc7 doc update 2022-02-14 10:03:52 -08:00
Kelly Brazil
67dbf05016 add type annotations 2022-02-14 09:58:31 -08:00
Kelly Brazil
4ac9f2e3da doc update 2022-02-14 09:37:37 -08:00
Kelly Brazil
3f5f6e39a7 formatting 2022-02-14 09:20:16 -08:00
Kelly Brazil
4723db8e3c doc updates 2022-02-14 09:14:46 -08:00
Kelly Brazil
ca914ec77d add nodata test 2022-02-14 09:14:38 -08:00
Kelly Brazil
dcc7f3f357 Merge pull request #204 from lyterk/xrandr
New parser: xrandr
2022-02-13 17:45:53 -08:00
Kevin Lyter
cbdc666236 Return empty object if no results and filenames
- If no results are returned, return {} instead of {"screens": [],
"unassociated_devices": []}
- simple_xrandr -> xrandr_simple
2022-02-09 22:06:23 -08:00
Kelly Brazil
184ef3a1fa doc update 2022-02-08 14:45:33 -08:00
Kelly Brazil
c732f75944 doc update 2022-02-08 14:43:14 -08:00
Kelly Brazil
7a1ae4f5fc add library tests 2022-02-08 13:32:22 -08:00
Kelly Brazil
d04bc3757c add xrandr 2022-02-08 07:33:26 -08:00
Kelly Brazil
73e8391653 formatting 2022-02-07 16:58:06 -08:00
Kelly Brazil
f6c1463c15 formatting 2022-02-07 16:31:43 -08:00
Kelly Brazil
d392c7f901 doc update 2022-02-07 15:44:54 -08:00
Kelly Brazil
d0387f5820 add timestamp format hints for better performance 2022-02-07 15:44:46 -08:00
Kelly Brazil
76f92908a3 add format hints for performance optimization 2022-02-07 15:43:24 -08:00
Kelly Brazil
1a115da67b add lru_cache maxsize for python 3.7 support 2022-02-07 08:34:34 -08:00
Kelly Brazil
f0a37ccf30 use lru_cache for significant performance boost to timestamp 2022-02-07 08:30:11 -08:00
Kelly Brazil
f331f53a53 use !r formatting instead of quotes 2022-02-07 08:06:48 -08:00
Kelly Brazil
8611aff06b add examples 2022-02-07 06:42:35 -08:00
Kelly Brazil
2f3f78e8d3 refine streaming parsers 2022-02-07 06:29:17 -08:00
Kelly Brazil
d1e0ee6123 use new streaming functions 2022-02-06 08:56:18 -08:00
Kelly Brazil
45314c9808 move some functions to streaming 2022-02-06 08:55:42 -08:00
Kelly Brazil
df00945b46 move try/except inside for loop 2022-02-04 16:03:44 -08:00
Kelly Brazil
fda0050d86 add rsync-s tests 2022-02-04 14:39:45 -08:00
Kelly Brazil
a76d46f9ec refactor ignore_exceptions 2022-02-04 12:14:16 -08:00
Kevin Lyter
6b069a82d0 Add xrandr to lib.py 2022-02-03 22:40:40 -08:00
Kevin Lyter
6b793d0521 Clean up types
* | operator => Union[]
* Remove unused import Iterator
* Remove comment
2022-02-03 22:40:35 -08:00
Kevin Lyter
ce9103f7cc Delete old files in template folder 2022-02-03 18:12:46 -08:00
Kelly Brazil
671d6dee36 doc update 2022-02-03 15:47:46 -08:00
Kelly Brazil
49929c714c add add_jc_meta decorator 2022-02-03 15:44:18 -08:00
Kelly Brazil
2986771f07 require python v3.7 and above since v3.6 is now deprecated 2022-02-03 09:21:20 -08:00
Kevin Lyter
520082d963 New parser: xrandr
Tests passing, working as intended in plugin directory
2022-02-02 20:33:25 -08:00
Kelly Brazil
021e296d45 move variable inits and regexes up 2022-02-02 17:06:20 -08:00
Kelly Brazil
42e56fbcea move regex up 2022-02-02 17:05:53 -08:00
Kelly Brazil
a5b62a4055 add processing and docs 2022-02-02 16:03:14 -08:00
Kelly Brazil
be98c9b7f6 simplify try/except by moving outside for loop 2022-02-02 15:59:12 -08:00
Kelly Brazil
aceeb84507 doc update 2022-02-02 15:58:29 -08:00
Kelly Brazil
1391063217 first draft rsync streaming parser 2022-02-02 11:49:39 -08:00
Kelly Brazil
52157addd0 fix compatible list 2022-02-02 11:49:24 -08:00
Kelly Brazil
ec0bc6615e formatting 2022-02-01 19:20:19 -08:00
Kelly Brazil
2f80800e38 simplify all_parser_info comprehension 2022-02-01 19:06:41 -08:00
Kelly Brazil
3959d3347c doc update 2022-02-01 18:33:07 -08:00
Kelly Brazil
b57d25c69a clean up return type for parser_info 2022-02-01 18:30:37 -08:00
Kelly Brazil
63e43a7cab doc updates 2022-02-01 17:57:12 -08:00
Kelly Brazil
21719f9a26 type annotation updates 2022-02-01 17:54:22 -08:00
Kelly Brazil
96ec70de4f remove unneeded optional 2022-02-01 17:18:55 -08:00
Kelly Brazil
a15a1967dc fix typo 2022-02-01 17:18:39 -08:00
Kelly Brazil
a10d756629 fixy mypy issues 2022-02-01 16:49:31 -08:00
Kelly Brazil
0700dc7a64 remove cygwin from compatible 2022-02-01 16:42:51 -08:00
Kelly Brazil
ca654b2140 fix parser order 2022-02-01 16:42:10 -08:00
Kelly Brazil
4ff3b87c1c remove future field from docstring 2022-02-01 16:18:38 -08:00
Kelly Brazil
ea244fb7a9 formatting 2022-02-01 16:17:03 -08:00
Kelly Brazil
8061f30e6f add centos -i nochange test 2022-02-01 16:16:33 -08:00
Kelly Brazil
8f3b12e81e add fixes for mac -i output 2022-02-01 14:52:51 -08:00
Kelly Brazil
d0694ce0db add nochange log test for mac 2022-02-01 14:20:53 -08:00
Kelly Brazil
0cd4c4bc7f add nochange tests 2022-02-01 13:58:51 -08:00
Kelly Brazil
12f90c349c update regexes for unchanged files 2022-02-01 13:54:25 -08:00
Kelly Brazil
26b8a1f167 remove packages from binaries and packages header 2022-02-01 09:58:18 -08:00
Kelly Brazil
3abe382c06 add examples 2022-01-31 16:01:42 -08:00
Kelly Brazil
1e2edc2c7b add timestamp 2022-01-31 15:54:05 -08:00
Kelly Brazil
5fe032a674 fix typo 2022-01-31 13:44:44 -08:00
Kelly Brazil
e825c02df1 add rsync tests 2022-01-31 13:23:31 -08:00
Kelly Brazil
a4a4d170b5 update docstring 2022-01-31 13:23:22 -08:00
Kelly Brazil
d0fcd523cb fix process conversions 2022-01-31 11:13:23 -08:00
Kelly Brazil
f72b7dc75d change keyname to files and remove future key 2022-01-30 16:37:45 -08:00
Kelly Brazil
4101dc6bf7 add log-file support 2022-01-30 16:21:03 -08:00
Kelly Brazil
ea5011b616 updated schema. add log-file option support 2022-01-29 17:24:43 -08:00
Kelly Brazil
d6de81747f add int/float conversions 2022-01-28 15:00:05 -08:00
Kelly Brazil
38f04b1c96 add summary 2022-01-28 14:45:01 -08:00
Kelly Brazil
84169e1a91 add rsync parser 2022-01-28 14:08:43 -08:00
Kelly Brazil
1f96586a5e reorder imports 2022-01-28 14:08:21 -08:00
Kelly Brazil
681176e4c9 Merge pull request #203 from kellyjonbrazil/dev
Dev v1.18.2
2022-01-27 16:53:37 -08:00
Kelly Brazil
8bb2663522 date update 2022-01-27 16:49:46 -08:00
Kelly Brazil
663abf3139 clean up scripts 2022-01-27 16:14:14 -08:00
Kelly Brazil
f7ac41db95 final doc update 2022-01-27 13:27:50 -08:00
Kelly Brazil
5502cda9e5 add additional test for dict inside list for all_parser_info() 2022-01-27 13:03:02 -08:00
Kelly Brazil
a2b165565f add lib tests for new functions 2022-01-27 12:54:44 -08:00
Kelly Brazil
b426369815 use all_parser_info() from lib in about function 2022-01-27 07:45:20 -08:00
Kelly Brazil
ac0840cc0a fix typo 2022-01-26 20:51:18 -08:00
Kelly Brazil
ee98ab0a4a doc update 2022-01-26 20:42:20 -08:00
Kelly Brazil
2adec2c003 update type hints with mypy help 2022-01-26 20:40:03 -08:00
Kelly Brazil
f19c9c71bf add type hints 2022-01-26 18:39:14 -08:00
Kelly Brazil
e93adf1884 fix doc 2022-01-26 18:09:30 -08:00
Kelly Brazil
254c4fc507 add new functions 2022-01-26 18:05:00 -08:00
Kelly Brazil
74d5f60d14 update console interview description 2022-01-26 17:17:40 -08:00
Kelly Brazil
db7dc0634b make **kwargs optional 2022-01-26 17:12:35 -08:00
Kelly Brazil
e156b0db45 add type hints 2022-01-26 17:08:03 -08:00
Kelly Brazil
50adc05fbd formatting 2022-01-26 16:58:48 -08:00
Kelly Brazil
446cac7c21 doc update 2022-01-26 16:55:39 -08:00
Kelly Brazil
28ffe3076b formatting 2022-01-26 16:34:23 -08:00
Kelly Brazil
d4d5e206ca type hints update 2022-01-26 15:54:36 -08:00
Kelly Brazil
42fbe40a4a simplify type hints 2022-01-26 15:54:18 -08:00
Kelly Brazil
27e4a120e2 remove trailing comma 2022-01-26 15:31:18 -08:00
Kelly Brazil
b5d5b7c73a remove private classes 2022-01-26 15:01:42 -08:00
Kelly Brazil
e7471556ba remove sed lines 2022-01-26 14:39:11 -08:00
Kelly Brazil
640a21341b fix indentation 2022-01-26 14:38:57 -08:00
Kelly Brazil
f5befad3e4 move docstring under __init__ 2022-01-26 14:21:06 -08:00
Kelly Brazil
f8223023c3 change header depth 2022-01-26 14:16:04 -08:00
Kelly Brazil
7028e87f9b remove TOC for parsers 2022-01-26 13:03:51 -08:00
Kelly Brazil
590728f9c1 try new pydoc-markdown formatting options 2022-01-26 11:50:25 -08:00
Kelly Brazil
7cc147fe2d increase heading size 2022-01-25 19:28:37 -08:00
Kelly Brazil
3cfb3965bb formatting 2022-01-25 19:28:04 -08:00
Kelly Brazil
155d421322 formatting 2022-01-25 19:18:54 -08:00
Kelly Brazil
d3e10bb87b add lsusb docs 2022-01-25 18:59:40 -08:00
Kelly Brazil
fd5433ee62 parse docstring formatting 2022-01-25 18:58:09 -08:00
Kelly Brazil
4568f2d06e formatting for parse docstring 2022-01-25 18:51:56 -08:00
Kelly Brazil
c36e513d1b formatting 2022-01-25 18:42:55 -08:00
Kelly Brazil
8e089baf3f remove info class from docs 2022-01-25 18:38:26 -08:00
Kelly Brazil
386f6c317e update markdown processor settings 2022-01-25 18:03:34 -08:00
Kelly Brazil
75cd84ce8a try new markdown conversion 2022-01-25 17:07:47 -08:00
Kelly Brazil
6fad44e35d fix type hint 2022-01-25 16:28:29 -08:00
Kelly Brazil
1caac750da Update type hints 2022-01-25 16:27:29 -08:00
Kelly Brazil
16370dcb3d update type hints 2022-01-25 15:49:48 -08:00
Kelly Brazil
c1302f2573 add type-hints to public api 2022-01-25 15:49:31 -08:00
Kelly Brazil
6f0ffe0955 docu update 2022-01-25 15:48:00 -08:00
Kelly Brazil
1f89745fe7 version bump 2022-01-25 11:17:18 -08:00
Kelly Brazil
a46ac18ef7 doc update 2022-01-25 10:47:05 -08:00
Kelly Brazil
1a05f1c575 add parser info functions. move _get_parser functionality from cli to lib 2022-01-25 10:46:58 -08:00
Kelly Brazil
08f818aa42 Merge pull request #199 from kellyjonbrazil/master
sync to dev
2022-01-25 00:45:53 +00:00
Kelly Brazil
b3896650c2 revert column formatting 2022-01-23 13:40:50 -08:00
Kelly Brazil
f285539526 conform to 80 columns 2022-01-23 13:36:22 -08:00
Kelly Brazil
a896dcdf3b formatting 2022-01-23 13:14:00 -08:00
Kelly Brazil
0a187d4ed0 add console interview links 2022-01-23 10:04:19 -08:00
Kelly Brazil
2d65bc57d5 add quotes 2022-01-21 16:58:45 -08:00
Kelly Brazil
ab63809fde update description 2022-01-21 16:13:00 -08:00
Kelly Brazil
6f04707dc6 add python package doc info to top of page 2022-01-21 15:33:43 -08:00
Kelly Brazil
d14a86a9b5 fix typo 2022-01-21 15:29:46 -08:00
Kelly Brazil
8e6a31d3da minor fix for macOS binary 2022-01-21 14:08:19 -08:00
Kelly Brazil
6e7b6afe87 Merge pull request #198 from kellyjonbrazil/dev
Dev v1.18.0
2022-01-21 13:52:16 -08:00
Kelly Brazil
027c231097 formatting 2022-01-21 13:48:38 -08:00
Kelly Brazil
f1cf7d1f95 add helper function info 2022-01-21 12:51:26 -08:00
Kelly Brazil
df611cc263 formatting 2022-01-21 12:41:52 -08:00
Kelly Brazil
0f3143bbbb formatting 2022-01-21 12:39:22 -08:00
Kelly Brazil
c280757b76 formatting 2022-01-21 12:35:48 -08:00
Kelly Brazil
d30b9d84ef formatting 2022-01-21 12:33:23 -08:00
Kelly Brazil
50ded1dbd9 doc update 2022-01-21 12:31:03 -08:00
Kelly Brazil
e319aea5a4 add doc version info 2022-01-21 12:29:36 -08:00
Kelly Brazil
ba86509c1d simplify OSError exception handling 2022-01-21 12:15:34 -08:00
Kelly Brazil
0a9279ae6b doc update 2022-01-21 12:15:16 -08:00
Kelly Brazil
a13dde12af change raw output wording 2022-01-21 07:42:03 -08:00
Kelly Brazil
e2ed358de1 changelog update 2022-01-20 15:31:24 -08:00
Kelly Brazil
a2cd366621 Delete _config.yml 2022-01-20 15:01:49 -08:00
Kelly Brazil
15addd9bfc doc fix 2022-01-20 09:59:23 -08:00
Kelly Brazil
a4e34b0053 add universal parser docs 2022-01-20 09:46:24 -08:00
Kelly Brazil
d09529ac30 changelog update 2022-01-20 09:40:34 -08:00
Kelly Brazil
553097b505 docstring update 2022-01-20 09:40:08 -08:00
Kelly Brazil
49c5568577 module doc update 2022-01-20 07:49:45 -08:00
Kelly Brazil
6962b9ee8a formatting 2022-01-19 22:24:59 -08:00
Kelly Brazil
b4575a3f78 add lib docs 2022-01-19 22:20:36 -08:00
Kelly Brazil
35b54d235d add python package doc info 2022-01-19 21:53:13 -08:00
Kelly Brazil
583a5757e4 formatting 2022-01-19 21:32:21 -08:00
Kelly Brazil
f355333eee formatting 2022-01-19 19:27:46 -08:00
Kelly Brazil
4d7df10960 formatting 2022-01-19 19:24:37 -08:00
Kelly Brazil
66b2c28f4b formatting 2022-01-19 19:22:08 -08:00
Kelly Brazil
299a9c6d88 formatting 2022-01-19 19:19:25 -08:00
Kelly Brazil
bd391d979c add lib function docs 2022-01-19 19:18:03 -08:00
Kelly Brazil
7309bd2282 add get_help 2022-01-19 18:47:44 -08:00
Kelly Brazil
ce84c09d33 add get_help() 2022-01-19 18:44:26 -08:00
Kelly Brazil
b4fffbb647 formatting 2022-01-19 17:30:14 -08:00
Kelly Brazil
3701b4198a formatting 2022-01-19 17:29:22 -08:00
Kelly Brazil
d4c34098fa formatting 2022-01-19 11:31:29 -08:00
Kelly Brazil
b3c531193b formatting 2022-01-19 11:08:59 -08:00
Kelly Brazil
1d0e07c77b formatting 2022-01-19 10:31:46 -08:00
Kelly Brazil
06a322cf9c rename tests and add conversion function tests 2022-01-19 10:31:36 -08:00
Kelly Brazil
623d148712 doc update 2022-01-19 09:30:53 -08:00
Kelly Brazil
647e83d043 add test to ensure there are zero plugin parsers installed during tests 2022-01-19 09:29:09 -08:00
Kelly Brazil
91a5544644 doc update 2022-01-19 09:28:35 -08:00
Kelly Brazil
a1190998ae add jc and jc.lib tests 2022-01-19 09:15:24 -08:00
Kelly Brazil
097d7a1850 simplify __init__ 2022-01-19 09:15:11 -08:00
Kelly Brazil
302bf72e72 Update high-level API docs 2022-01-18 15:38:03 -08:00
Kelly Brazil
2c42baf3a4 add new high-level api info 2022-01-18 14:18:12 -08:00
Kelly Brazil
03feb89c84 add module list info 2022-01-18 13:46:11 -08:00
Kelly Brazil
9dd553192f doc update 2022-01-18 13:40:09 -08:00
Kelly Brazil
fa3f02e9d1 version bump 2022-01-18 13:39:51 -08:00
Kelly Brazil
0a9dde58c5 add jc.parse() high-level API 2022-01-18 13:10:14 -08:00
283 changed files with 12488 additions and 2828 deletions

View File

@@ -1,5 +1,38 @@
jc changelog
20220305 v1.18.5
- Fix date parser to ensure AM/PM period string is always uppercase
20220304 v1.18.4
- Add nmcli command parser tested on linux
- Enhance parse error messages at the cli
- Add standard and streaming parser list functions to the public API
- Enhance python developer documentation formatting
20220214 v1.18.3
- Add rsync command and log file parser tested on linux and macOS
- Add rsync command and log file streaming parser tested on linux and macOS
- Add xrandr command parser tested on linux
- Enhance timestamp performance with caching and format hints
- Refactor ignore_exceptions functionality in streaming parsers
- Fix man page in packages
20220127 v1.18.2
- Fix for plugin parsers with underscores in the name
- Add type hints to public API functions
- Add plugin attribute to plugin parser metadata
- Add C locale hint to parsing error messages
- Refactor more cli code into lib
20220121 v1.18.1
- Minor fix for MacOS binary
20220121 v1.18.0
- Add high-level parse API for built-in and plugin parsers
- Add python module developer documentation
- Enhance magic syntax exception messages
- Enhance documentation formatting
20220106 v1.17.7
- Add stat command streaming parser tested on linux and macOS

View File

@@ -2387,6 +2387,47 @@ netstat -i | jc --netstat -p # or: jc -p netstat -i
}
]
```
### nmcli
```bash
nmcli connection show ens33 | jc --nmcli -p # or jc -p nmcli connection show ens33
```
```json
[
{
"connection_id": "ens33",
"connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744",
"connection_stable_id": null,
"connection_type": "802-3-ethernet",
"connection_interface_name": "ens33",
"connection_autoconnect": "yes",
"ip4_address_1": "192.168.71.180/24",
"ip4_gateway": "192.168.71.2",
"ip4_route_1": {
"dst": "0.0.0.0/0",
"nh": "192.168.71.2",
"mt": 100
},
"ip4_route_2": {
"dst": "192.168.71.0/24",
"nh": "0.0.0.0",
"mt": 100
},
"ip4_dns_1": "192.168.71.2",
"ip4_domain_1": "localdomain",
"dhcp4_option_1": {
"name": "broadcast_address",
"value": "192.168.71.255"
},
"ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64",
"ip6_gateway": null,
"ip6_route_1": {
"dst": "fe80::/64",
"nh": "::",
"mt": 100
}
}
]
```
### ntpq
```bash
ntpq -p | jc --ntpq -p # or: jc -p ntpq -p
@@ -2743,6 +2784,39 @@ rpm_qia | jc --rpm_qi -p # or: jc -p rpm -qia
}
]
```
### rsync
```bash
rsync -i -a source/ dest | jc --rsync -p # or jc -p rsync -i -a source/ dest
```
```json
[
{
"summary": {
"sent": 1708,
"received": 8209,
"bytes_sec": 19834.0,
"total_size": 235,
"speedup": 0.02
},
"files": [
{
"filename": "./",
"metadata": ".d..t......",
"update_type": "not updated",
"file_type": "directory",
"checksum_or_value_different": false,
"size_different": false,
"modification_time_different": true,
"permissions_different": false,
"owner_different": false,
"group_different": false,
"acl_different": false,
"extended_attribute_different": false
}
]
}
]
```
### sfdisk
```bash
sfdisk -l | jc --sfdisk -p # or jc -p sfdisk -l
@@ -3751,6 +3825,68 @@ cat cd_catalog.xml | jc --xml -p
}
}
```
### xrandr
```bash
$ xrandr | jc --xrandr -p # or jc -p xrandr
```
```json
{
"screens": [
{
"screen_number": 0,
"minimum_width": 8,
"minimum_height": 8,
"current_width": 1920,
"current_height": 1080,
"maximum_width": 32767,
"maximum_height": 32767,
"associated_device": {
"associated_modes": [
{
"resolution_width": 1920,
"resolution_height": 1080,
"is_high_resolution": false,
"frequencies": [
{
"frequency": 60.03,
"is_current": true,
"is_preferred": true
},
{
"frequency": 59.93,
"is_current": false,
"is_preferred": false
}
]
},
{
"resolution_width": 1680,
"resolution_height": 1050,
"is_high_resolution": false,
"frequencies": [
{
"frequency": 59.88,
"is_current": false,
"is_preferred": false
}
]
}
],
"is_connected": true,
"is_primary": true,
"device_name": "eDP1",
"resolution_width": 1920,
"resolution_height": 1080,
"offset_width": 0,
"offset_height": 0,
"dimension_width": 310,
"dimension_height": 170
}
}
],
"unassociated_devices": []
}
```
### YAML files
```bash
cat istio.yaml

View File

@@ -1,3 +1,2 @@
include jc/man/jc.1.gz
include man/jc.1
include CHANGELOG

247
README.md
View File

@@ -1,60 +1,83 @@
![Tests](https://github.com/kellyjonbrazil/jc/workflows/Tests/badge.svg?branch=master)
![Pypi](https://img.shields.io/pypi/v/jc.svg)
> Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers
> Try the `jc` [web demo](https://jc-web-demo.herokuapp.com/)
> JC is [now available](https://galaxy.ansible.com/community/general) as an Ansible filter plugin in the `community.general` collection. See this [blog post](https://blog.kellybrazil.com/2020/08/30/parsing-command-output-in-ansible-with-jc/) for an example.
> JC is [now available](https://galaxy.ansible.com/community/general) as an
Ansible filter plugin in the `community.general` collection. See this
[blog post](https://blog.kellybrazil.com/2020/08/30/parsing-command-output-in-ansible-with-jc/)
for an example.
# JC
JSON CLI output utility
JSON Convert
`jc` JSONifies the output of many CLI tools and file-types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and file-types.
`jc` JSONifies the output of many CLI tools and file-types for easier parsing in
scripts. See the [**Parsers**](#parsers) section for supported commands and
file-types.
```bash
dig example.com | jc --dig
```
```json
[{"id":38052,"opcode":"QUERY","status":"NOERROR","flags":["qr","rd","ra"],"query_num":1,"answer_num":1,
"authority_num":0,"additional_num":1,"opt_pseudosection":{"edns":{"version":0,"flags":[],"udp":4096}},"question":
{"name":"example.com.","class":"IN","type":"A"},"answer":[{"name":"example.com.","class":"IN","type":"A","ttl":
39049,"data":"93.184.216.34"}],"query_time":49,"server":"2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)","when":
"Fri Apr 16 16:09:00 PDT 2021","rcvd":56,"when_epoch":1618614540,"when_epoch_utc":null}]
[{"id":38052,"opcode":"QUERY","status":"NOERROR","flags":["qr","rd","ra"],
"query_num":1,"answer_num":1,"authority_num":0,"additional_num":1,
"opt_pseudosection":{"edns":{"version":0,"flags":[],"udp":4096}},"question":
{"name":"example.com.","class":"IN","type":"A"},"answer":[{"name":
"example.com.","class":"IN","type":"A","ttl":39049,"data":"93.184.216.34"}],
"query_time":49,"server":"2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
"when":"Fri Apr 16 16:09:00 PDT 2021","rcvd":56,"when_epoch":1618614540,
"when_epoch_utc":null}]
```
This allows further command-line processing of output with tools like `jq` or [`jello`](https://github.com/kellyjonbrazil/jello) by piping commands:
This allows further command-line processing of output with tools like `jq`
or [`jello`](https://github.com/kellyjonbrazil/jello) by piping commands:
```bash
$ dig example.com | jc --dig | jq -r '.[].answer[].data'
93.184.216.34
```
or using the alternative "magic" syntax:
```bash
$ jc dig example.com | jq -r '.[].answer[].data'
93.184.216.34
```
The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary, or list of dictionaries, instead of JSON:
The `jc` parsers can also be used as python modules. In this case the output
will be a python dictionary, or list of dictionaries, instead of JSON:
```python
>>> import subprocess
>>> import jc.parsers.dig
>>>
>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
>>> data = jc.parsers.dig.parse(cmd_output)
>>> import jc
>>>
>>> data
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num':
1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp':
4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.',
'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': '93.184.216.34'}], 'query_time': 52, 'server':
'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': 'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56,
'when_epoch': 1618614780, 'when_epoch_utc': None}]
>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
>>> data = jc.parse('dig', cmd_output)
>>>
>>> data[0]['answer']
[{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data':
'93.184.216.34'}]
```
Two representations of the data are available. The default representation uses a strict schema per parser and converts known numbers to int/float JSON values. Certain known values of `None` are converted to JSON `null`, known boolean values are converted, and, in some cases, additional semantic context fields are added.
To access the raw, pre-processed JSON, use the `-r` cli option or the `raw=True` function parameter in `parse()`.
> For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or
see the [online documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs).
Schemas for each parser can be found at the documentation link beside each [**Parser**](#parsers) below.
Two representations of the data are available. The default representation uses a
strict schema per parser and converts known numbers to int/float JSON values.
Certain known values of `None` are converted to JSON `null`, known boolean
values are converted, and, in some cases, additional semantic context fields are
added.
To access the raw, pre-processed JSON, use the `-r` cli option or the `raw=True`
function parameter in `parse()`.
Schemas for each parser can be found at the documentation link beside each
[**Parser**](#parsers) below.
Release notes can be found [here](https://blog.kellybrazil.com/category/jc-news/).
## Why Would Anyone Do This!?
For more information on the motivations for this project, please see my blog post on [Bringing the Unix Philosophy to the 21st Century](https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/).
For more information on the motivations for this project, please see my blog
post on [Bringing the Unix Philosophy to the 21st Century](https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/) and my [interview with Console](https://console.substack.com/p/console-89).
See also:
- [libxo on FreeBSD](http://juniper.github.io/libxo/libxo-manual.html)
@@ -70,7 +93,10 @@ Use Cases:
- [Nornir command output parsing](https://blog.kellybrazil.com/2020/12/09/parsing-command-output-in-nornir-with-jc/)
## Installation
There are several ways to get `jc`. You can install via `pip`, OS package repositories, via DEB/RPM/MSI packaged binaries for linux and Windows, or by downloading the correct binary for your architecture and running it anywhere on your filesystem.
There are several ways to get `jc`. You can install via `pip`, OS package
[repositories](https://repology.org/project/jc/versions), or by downloading the
correct [binary](https://github.com/kellyjonbrazil/jc/releases) for your
architecture and running it anywhere on your filesystem.
### Pip (macOS, linux, unix, Windows)
```bash
@@ -79,7 +105,7 @@ pip3 install jc
### OS Package Repositories
| OS | Command |
| OS | Command |
|-----------------------|-------------------------------------------------------------------------------|
| Debian/Ubuntu linux | `apt-get install jc` |
| Fedora linux | `dnf install jc` |
@@ -93,19 +119,26 @@ pip3 install jc
> For more OS Packages, see https://repology.org/project/jc/versions.
### Binaries and Packages
For precompiled binaries and packages, see [Releases](https://github.com/kellyjonbrazil/jc/releases) on Github.
### Binaries
For precompiled binaries, see [Releases](https://github.com/kellyjonbrazil/jc/releases)
on Github.
## Usage
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT`.
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the
previous command's output to `STDOUT`.
```bash
COMMAND | jc PARSER [OPTIONS]
```
Alternatively, the "magic" syntax can be used by prepending `jc` to the command to be converted. Options can be passed to `jc` immediately before the command is given. (Note: command aliases and shell builtins are not supported)
Alternatively, the "magic" syntax can be used by prepending `jc` to the command
to be converted. Options can be passed to `jc` immediately before the command is
given. (Note: command aliases and shell builtins are not supported)
```bash
jc [OPTIONS] COMMAND
```
The JSON output can be compact (default) or pretty formatted with the `-p` option.
The JSON output can be compact (default) or pretty formatted with the `-p`
option.
### Parsers
@@ -157,6 +190,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
- `--lsusb` enables the `lsusb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb))
- `--mount` enables the `mount` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mount))
- `--netstat` enables the `netstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat))
- `--nmcli` enables the `nmcli` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli))
- `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq))
- `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd))
- `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping))
@@ -166,6 +200,8 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
- `--ps` enables the `ps` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ps))
- `--route` enables the `route` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/route))
- `--rpm-qi` enables the `rpm -qi` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/rpm_qi))
- `--rsync` enables the `rsync` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/rsync))
- `--rsync-s` enables the `rsync` command streaming parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/rsync_s))
- `--sfdisk` enables the `sfdisk` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/sfdisk))
- `--shadow` enables the `/etc/shadow` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/shadow))
- `--ss` enables the `ss` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ss))
@@ -192,27 +228,37 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
- `--wc` enables the `wc` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/wc))
- `--who` enables the `who` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/who))
- `--xml` enables the XML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/xml))
- `--xrandr` enables the `xrandr` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/xrandr))
- `--yaml` enables the YAML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/yaml))
- `--zipinfo` enables the `zipinfo` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/zipinfo))
### Options
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of course!)
- `-C` force color output even when using pipes (overrides `-m` and the `NO_COLOR` env variable)
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use `-dd` for verbose debugging)
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of
course!)
- `-C` force color output even when using pipes (overrides `-m` and the
`NO_COLOR` env variable)
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use
`-dd` for verbose debugging)
- `-h` help. Use `jc -h --parser_name` for parser documentation
- `-m` monochrome JSON output
- `-p` pretty format the JSON output
- `-q` quiet mode. Suppresses parser warning messages (use `-qq` to ignore streaming parser errors)
- `-r` raw output. Provides a more literal JSON output, typically with string values and no additional semantic processing
- `-q` quiet mode. Suppresses parser warning messages (use `-qq` to ignore
streaming parser errors)
- `-r` raw output. Provides a more literal JSON output, typically with string
values and no additional semantic processing
- `-u` unbuffer output
- `-v` version information
### Exit Codes
Any fatal errors within `jc` will generate an exit code of `100`, otherwise the exit code will be `0`. When using the "magic" syntax (e.g. `jc ifconfig eth0`), `jc` will store the exit code of the program being parsed and add it to the `jc` exit code. This way it is easier to determine if an error was from the parsed program or `jc`.
Any fatal errors within `jc` will generate an exit code of `100`, otherwise the
exit code will be `0`. When using the "magic" syntax (e.g. `jc ifconfig eth0`),
`jc` will store the exit code of the program being parsed and add it to the `jc`
exit code. This way it is easier to determine if an error was from the parsed
program or `jc`.
Consider the following examples using `ifconfig`:
| `ifconfig` exit code | `jc` exit code | Combined exit code | Interpretation |
| `ifconfig` exit code | `jc` exit code | Combined exit code | Interpretation |
|----------------------|----------------|--------------------|------------------------------------|
| `0` | `0` | `0` | No errors |
| `1` | `0` | `1` | Error in `ifconfig` |
@@ -221,11 +267,16 @@ Consider the following examples using `ifconfig`:
### Setting Custom Colors via Environment Variable
You can specify custom colors via the `JC_COLORS` environment variable. The `JC_COLORS` environment variable takes four comma separated string values in the following format:
You can specify custom colors via the `JC_COLORS` environment variable. The
`JC_COLORS` environment variable takes four comma separated string values in
the following format:
```bash
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
```
Where colors are: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `gray`, `brightblack`, `brightred`, `brightgreen`, `brightyellow`, `brightblue`, `brightmagenta`, `brightcyan`, `white`, or `default`
Where colors are: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`,
`gray`, `brightblack`, `brightred`, `brightgreen`, `brightyellow`, `brightblue`,
`brightmagenta`, `brightcyan`, `white`, or `default`
For example, to set to the default colors:
```bash
@@ -237,16 +288,33 @@ JC_COLORS=default,default,default,default
```
### Disable Colors via Environment Variable
You can set the [`NO_COLOR`](http://no-color.org/) environment variable to any value to disable color output in `jc`. Note that using the `-C` option to force color output will override both the `NO_COLOR` environment variable and the `-m` option.
You can set the [`NO_COLOR`](http://no-color.org/) environment variable to any
value to disable color output in `jc`. Note that using the `-C` option to force
color output will override both the `NO_COLOR` environment variable and the `-m`
option.
### Streaming Parsers
Most parsers load all of the data from STDIN, parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. `ls-s` and `ping-s`) that immediately start processing and outputing the data line-by-line as [JSON Lines](https://jsonlines.org/) (aka [NDJSON](http://ndjson.org/)) while it is being received from STDIN. This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. `ls -lR /`) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below.
Most parsers load all of the data from STDIN, parse it, then output the entire
JSON document serially. There are some streaming parsers (e.g. `ls-s` and
`ping-s`) that immediately start processing and outputing the data line-by-line
as [JSON Lines](https://jsonlines.org/) (aka [NDJSON](http://ndjson.org/)) while
it is being received from STDIN. This can significantly reduce the amount of
memory required to parse large amounts of command output (e.g. `ls -lR /`) and
can sometimes process the data more quickly. Streaming parsers have slightly
different behavior than standard parsers as outlined below.
> Note: Streaming parsers cannot be used with the "magic" syntax
#### Ignoring Errors
You may want to ignore parsing errors when using streaming parsers since these may be used in long-lived processing pipelines and errors can break the pipe. To ignore parsing errors, use the `-qq` cli option or the `ignore_exceptions=True` argument with the `parse()` function. This will add a `_jc_meta` object to the JSON output with a `success` attribute. If `success` is `true`, then there were no issues parsing the line. If `success` is `false`, then a parsing issue was found and `error` and `line` fields will be added to include a short error description and the contents of the unparsable line, respectively:
You may want to ignore parsing errors when using streaming parsers since these
may be used in long-lived processing pipelines and errors can break the pipe. To
ignore parsing errors, use the `-qq` cli option or the `ignore_exceptions=True`
argument with the `parse()` function. This will add a `_jc_meta` object to the
JSON output with a `success` attribute. If `success` is `true`, then there were
no issues parsing the line. If `success` is `false`, then a parsing issue was
found and `error` and `line` fields will be added to include a short error
description and the contents of the unparsable line, respectively:
Successfully parsed line with `-qq` option:
```json
@@ -257,6 +325,7 @@ Successfully parsed line with `-qq` option:
}
}
```
Unsuccessfully parsed line with `-qq` option:
```json
{
@@ -270,54 +339,76 @@ Unsuccessfully parsed line with `-qq` option:
#### Unbuffering Output
Most operating systems will buffer output that is being piped from process to process. The buffer is usually around 4KB. When viewing the output in the terminal the OS buffer is not engaged so output is immediately displayed on the screen. When piping multiple processes together, though, it may seem as if the output is hanging when the input data is very slow (e.g. `ping`):
Most operating systems will buffer output that is being piped from process to
process. The buffer is usually around 4KB. When viewing the output in the
terminal the OS buffer is not engaged so output is immediately displayed on the
screen. When piping multiple processes together, though, it may seem as if the
output is hanging when the input data is very slow (e.g. `ping`):
```
$ ping 1.1.1.1 | jc --ping-s | jq
<slow output>
```
This is because the OS engages the 4KB buffer between `jc` and `jq` in this example. To display the data on the terminal in realtime, you can disable the buffer with the `-u` (unbuffer) cli option:
This is because the OS engages the 4KB buffer between `jc` and `jq` in this
example. To display the data on the terminal in realtime, you can disable the
buffer with the `-u` (unbuffer) cli option:
```
$ ping 1.1.1.1 | jc --ping-s -u | jq
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"1","ttl":"128","time_ms":"24.6","duplicate":false}
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"2","ttl":"128","time_ms":"26.8","duplicate":false}
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","respons...}
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","respons...}
...
```
> Note: Unbuffered output can be slower for large data streams.
#### Using Streaming Parsers as Python Modules
Streaming parsers accept any iterable object and return a generator iterator object allowing lazy processing of the data. The input data should iterate on lines of string data. Examples of good input data are `sys.stdin` or `str.splitlines()`.
Streaming parsers accept any iterable object and return an iterator object
(generator) allowing lazy processing of the data. The input data should
iterate on lines of string data. Examples of good input data are `sys.stdin` or
`str.splitlines()`.
To use the generator object in your code, simply loop through it or use the [next()](https://docs.python.org/3/library/functions.html#next) builtin function:
To use the generator object in your code, simply loop through it or use the
[next()](https://docs.python.org/3/library/functions.html#next) builtin
function:
```python
import jc.parsers.ls_s
import jc
result = jc.parsers.ls_s.parse(ls_command_output.splitlines())
result = jc.parse('ls_s', ls_command_output.splitlines())
for item in result:
print(item["filename"])
```
### Custom Parsers
Custom local parser plugins may be placed in a `jc/jcparsers` folder in your local **"App data directory"**:
Custom local parser plugins may be placed in a `jc/jcparsers` folder in your
local **"App data directory"**:
- Linux/unix: `$HOME/.local/share/jc/jcparsers`
- macOS: `$HOME/Library/Application Support/jc/jcparsers`
- Windows: `$LOCALAPPDATA\jc\jc\jcparsers`
Local parser plugins are standard python module files. Use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) or [`jc/parsers/foo_s.py (streaming)`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo_s.py) parser as a template and simply place a `.py` file in the `jcparsers` subfolder.
Local parser plugins are standard python module files. Use the
[`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py)
or [`jc/parsers/foo_s.py (streaming)`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo_s.py)
parser as a template and simply place a `.py` file in the `jcparsers` subfolder.
Local plugin filenames must be valid python module names, therefore must consist entirely of alphanumerics and start with a letter. Local plugins may override default parsers.
Local plugin filenames must be valid python module names, therefore must consist
entirely of alphanumerics and start with a letter. Local plugins may override
default parsers.
> Note: The application data directory follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
> Note: The application data directory follows the
[XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
### Caveats
#### Locale
For best results set the `LANG` locale environment variable to `C` or `en_US.UTF-8`. For example, either by setting directly on the command-line:
For best results set the `LANG` locale environment variable to `C` or
`en_US.UTF-8`. For example, either by setting directly on the command-line:
```
$ LANG=C date | jc --date
```
or by exporting to the environment before running commands:
```
$ export LANG=C
@@ -325,19 +416,30 @@ $ export LANG=C
#### Timezones
Some parsers have calculated epoch timestamp fields added to the output. Unless a timestamp field name has a `_utc` suffix it is considered naive. (i.e. based on the local timezone of the system the `jc` parser was run on).
Some parsers have calculated epoch timestamp fields added to the output. Unless
a timestamp field name has a `_utc` suffix it is considered naive. (i.e. based
on the local timezone of the system the `jc` parser was run on).
If a UTC timezone can be detected in the text of the command output, the timestamp will be timezone aware and have a `_utc` suffix on the key name. (e.g. `epoch_utc`) No other timezones are supported for aware timestamps.
If a UTC timezone can be detected in the text of the command output, the
timestamp will be timezone aware and have a `_utc` suffix on the key name.
(e.g. `epoch_utc`) No other timezones are supported for aware timestamps.
## Compatibility
Some parsers like `dig`, `xml`, `csv`, etc. will work on any platform. Other parsers that convert platform-specific output will generate a warning message if they are run on an unsupported platform. To see all parser information, including compatibility, run `jc -ap`.
Some parsers like `dig`, `xml`, `csv`, etc. will work on any platform. Other
parsers that convert platform-specific output will generate a warning message if
they are run on an unsupported platform. To see all parser information,
including compatibility, run `jc -ap`.
You may still use a parser on an unsupported platform - for example, you may want to parse a file with linux `lsof` output on an macOS or Windows laptop. In that case you can suppress the warning message with the `-q` cli option or the `quiet=True` function parameter in `parse()`:
You may still use a parser on an unsupported platform - for example, you may want
to parse a file with linux `lsof` output on an macOS or Windows laptop. In that
case you can suppress the warning message with the `-q` cli option or the
`quiet=True` function parameter in `parse()`:
macOS:
```bash
cat lsof.out | jc --lsof -q
```
or Windows:
```bash
type lsof.out | jc --lsof -q
@@ -357,22 +459,30 @@ Tested on:
- Windows 2019 Server
## Contributions
Feel free to add/improve code or parsers! You can use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) or [`jc/parsers/foo_s.py (streaming)`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo_s.py) parsers as a template and submit your parser with a pull request.
Feel free to add/improve code or parsers! You can use the
[`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py)
or [`jc/parsers/foo_s.py (streaming)`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo_s.py) parsers as a template and submit your parser with a pull request.
Please see the [Contributing Guidelines](https://github.com/kellyjonbrazil/jc/blob/master/CONTRIBUTING.md) for more information.
## Acknowledgments
- Local parser plugin feature contributed by [Dean Serenevy](https://github.com/duelafn)
- CI automation and code optimizations by [philippeitis](https://github.com/philippeitis)
- [`ifconfig-parser`](https://github.com/KnightWhoSayNi/ifconfig-parser) module by KnightWhoSayNi
- [`ifconfig-parser`](https://github.com/KnightWhoSayNi/ifconfig-parser) module
by KnightWhoSayNi
- [`xmltodict`](https://github.com/martinblech/xmltodict) module by Martín Blech
- [`ruamel.yaml`](https://pypi.org/project/ruamel.yaml) module by Anthon van der Neut
- [`ruamel.yaml`](https://pypi.org/project/ruamel.yaml) module by Anthon van
der Neut
- [`trparse`](https://github.com/lbenitez000/trparse) module by Luis Benitez
- Parsing [code](https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501) from Conor Heine adapted for some parsers
- Parsing [code](https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501)
from Conor Heine adapted for some parsers
- Excellent constructive feedback from [Ilya Sher](https://github.com/ilyash-b)
## Examples
Here are some examples of `jc` output. For more examples, see [here](https://kellyjonbrazil.github.io/jc/EXAMPLES) or the parser documentation.
Here are some examples of `jc` output. For more examples, see
[here](https://kellyjonbrazil.github.io/jc/EXAMPLES) or the parser
documentation.
### arp
```bash
arp | jc --arp -p # or: jc -p arp
@@ -780,7 +890,7 @@ ps axu | jc --ps -p # or: jc -p ps axu
"stat": "Ss",
"start": "Nov09",
"time": "0:08",
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
"command": "/usr/lib/systemd/systemd --switched-root --system --deseria..."
},
{
"user": "root",
@@ -812,7 +922,8 @@ ps axu | jc --ps -p # or: jc -p ps axu
```
### traceroute
```bash
traceroute -m 2 8.8.8.8 | jc --traceroute -p # or: jc -p traceroute -m 2 8.8.8.8
traceroute -m 2 8.8.8.8 | jc --traceroute -p
# or: jc -p traceroute -m 2 8.8.8.8
```
```json
{

View File

@@ -1,24 +1,107 @@
#!/bin/bash
# Generate docs.md
# requires pydoc-markdown 2.1.0.post1
# requires pydoc-markdown 4.6.1
readme_config=$(cat <<'EOF'
{
"processors": [
{
"type": "filter"
},
{
"type": "pydocmd"
}
],
"renderer": {
"type": "markdown",
"header_level_by_type": {
"Module": 1,
"Class": 3,
"Method": 3,
"Function": 3,
"Variable": 3
}
}
}
EOF
)
toc_config=$(cat <<'EOF'
{
"processors": [
{
"type": "filter"
},
{
"type": "pydocmd"
}
],
"renderer": {
"type": "markdown",
"render_toc": true,
"header_level_by_type": {
"Module": 1,
"Class": 3,
"Method": 3,
"Function": 3,
"Variable": 3
}
}
}
EOF
)
parser_config=$(cat <<'EOF'
{
"processors": [
{
"type": "filter",
"expression": "not name == \"info\" and not name.startswith(\"_\") and default()"
},
{
"type": "pydocmd"
}
],
"renderer": {
"type": "markdown",
"header_level_by_type": {
"Module": 1,
"Class": 3,
"Method": 3,
"Function": 3,
"Variable": 3
}
}
}
EOF
)
cd jc
echo Building docs for: package
pydocmd simple jc+ > ../docs/readme.md
pydoc-markdown -m jc "${readme_config}" > ../docs/readme.md
echo Building docs for: lib
pydoc-markdown -m jc.lib "${toc_config}" > ../docs/lib.md
echo Building docs for: utils
pydocmd simple utils+ > ../docs/utils.md
pydoc-markdown -m jc.utils "${toc_config}" > ../docs/utils.md
echo Building docs for: streaming
pydoc-markdown -m jc.streaming "${toc_config}" > ../docs/streaming.md
echo Building docs for: universal parser
pydoc-markdown -m jc.parsers.universal "${toc_config}" > ../docs/parsers/universal.md
# a bit of inception here... jc is being used to help
# automate the generation of its own documentation. :)
# pull jc parser objects into a bash array from jq
# filter out any plugin parsers
parsers=()
while read -r value
do
parsers+=("$value")
done < <(jc -a | jq -c '.parsers[]')
done < <(jc -a | jq -c '.parsers[] | select(.plugin != true)')
# iterate over the bash array
for parser in "${parsers[@]}"
do
parser_name=$(jq -r '.name' <<< "$parser")
@@ -29,8 +112,8 @@ do
echo "Building docs for: ${parser_name}"
echo "[Home](https://kellyjonbrazil.github.io/jc/)" > ../docs/parsers/"${parser_name}".md
pydocmd simple jc.parsers."${parser_name}"+ >> ../docs/parsers/"${parser_name}".md
echo "## Parser Information" >> ../docs/parsers/"${parser_name}".md
pydoc-markdown -m jc.parsers."${parser_name}" "${parser_config}" >> ../docs/parsers/"${parser_name}".md
echo "### Parser Information" >> ../docs/parsers/"${parser_name}".md
echo "Compatibility: ${compatible}" >> ../docs/parsers/"${parser_name}".md
echo >> ../docs/parsers/"${parser_name}".md
echo "Version ${version} by ${author} (${author_email})" >> ../docs/parsers/"${parser_name}".md

View File

@@ -1 +0,0 @@
theme: jekyll-theme-cayman

166
docs/lib.md Normal file
View File

@@ -0,0 +1,166 @@
# Table of Contents
* [jc.lib](#jc.lib)
* [parse](#jc.lib.parse)
* [parser\_mod\_list](#jc.lib.parser_mod_list)
* [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list)
* [standard\_parser\_mod\_list](#jc.lib.standard_parser_mod_list)
* [streaming\_parser\_mod\_list](#jc.lib.streaming_parser_mod_list)
* [parser\_info](#jc.lib.parser_info)
* [all\_parser\_info](#jc.lib.all_parser_info)
* [get\_help](#jc.lib.get_help)
<a id="jc.lib"></a>
# jc.lib
jc - JSON Convert
JC lib module
<a id="jc.lib.parse"></a>
### parse
```python
def parse(parser_mod_name: str,
data: Union[str, Iterable[str]],
quiet: bool = False,
raw: bool = False,
ignore_exceptions: bool = None,
**kwargs) -> Union[Dict, List[Dict], Iterator[Dict]]
```
Parse the string data using the supplied parser module.
This function provides a high-level API to simplify parser use. This
function will call built-in parsers and custom plugin parsers.
Example:
>>> import jc
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}
To get a list of available parser module names, use `parser_mod_list()`.
You can also use the lower-level parser modules directly:
>>> import jc.parsers.date
>>> jc.parsers.date.parse('Tue Jan 18 10:23:07 PST 2022')
Though, accessing plugin parsers directly is a bit more cumbersome, so
this higher-level API is recommended. Here is how you can access plugin
parsers without this API:
>>> import os
>>> import sys
>>> import jc.appdirs
>>> data_dir = jc.appdirs.user_data_dir('jc', 'jc')
>>> local_parsers_dir = os.path.join(data_dir, 'jcparsers')
>>> sys.path.append(local_parsers_dir)
>>> import my_custom_parser
>>> my_custom_parser.parse('command_data')
Parameters:
parser_mod_name: (string) name of the parser module. This
function will accept module_name,
cli-name, and --argument-name
variants of the module name.
data: (string or data to parse (string for normal
iterator) parsers, iterator of strings for
streaming parsers)
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
(streaming parsers only)
Returns:
Standard Parsers: Dictionary or List of Dictionaries
Streaming Parsers: Generator Object containing Dictionaries
<a id="jc.lib.parser_mod_list"></a>
### parser\_mod\_list
```python
def parser_mod_list() -> List[str]
```
Returns a list of all available parser module names.
<a id="jc.lib.plugin_parser_mod_list"></a>
### plugin\_parser\_mod\_list
```python
def plugin_parser_mod_list() -> List[str]
```
Returns a list of plugin parser module names. This function is a
subset of `parser_mod_list()`.
<a id="jc.lib.standard_parser_mod_list"></a>
### standard\_parser\_mod\_list
```python
def standard_parser_mod_list() -> List[str]
```
Returns a list of standard parser module names. This function is a
subset of `parser_mod_list()` and does not contain any streaming
parsers.
<a id="jc.lib.streaming_parser_mod_list"></a>
### streaming\_parser\_mod\_list
```python
def streaming_parser_mod_list() -> List[str]
```
Returns a list of streaming parser module names. This function is a
subset of `parser_mod_list()`.
<a id="jc.lib.parser_info"></a>
### parser\_info
```python
def parser_info(parser_mod_name: str) -> Dict
```
Returns a dictionary that includes the module metadata.
This function will accept **module_name**, **cli-name**, and
**--argument-name** variants of the module name string.
<a id="jc.lib.all_parser_info"></a>
### all\_parser\_info
```python
def all_parser_info() -> List[Dict]
```
Returns a list of dictionaries that includes metadata for all modules.
<a id="jc.lib.get_help"></a>
### get\_help
```python
def get_help(parser_mod_name: str) -> None
```
Show help screen for the selected parser.
This function will accept **module_name**, **cli-name**, and
**--argument-name** variants of the module name string.

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.acpi"></a>
# jc.parsers.acpi
jc - JSON CLI output utility `acpi` command output parser
jc - JSON Convert `acpi` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('acpi', acpi_command_output)
or
import jc.parsers.acpi
result = jc.parsers.acpi.parse(acpi_command_output)
@@ -225,16 +232,12 @@ Examples:
}
]
<a id="jc.parsers.acpi.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -242,14 +245,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.airport"></a>
# jc.parsers.airport
jc - JSON CLI output utility `airport -I` command output parser
jc - JSON Convert `airport -I` command output parser
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('airport', airport_command_output)
or
import jc.parsers.airport
result = jc.parsers.airport.parse(airport_command_output)
@@ -78,16 +85,12 @@ Examples:
"channel": "48,80"
}
<a id="jc.parsers.airport.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -95,14 +98,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: darwin
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.airport_s"></a>
# jc.parsers.airport_s
jc - JSON CLI output utility `airport -s` command output parser
# jc.parsers.airport\_s
jc - JSON Convert `airport -s` command output parser
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('airport_s', airport_s_command_output)
or
import jc.parsers.airport_s
result = jc.parsers.airport_s.parse(airport_s_command_output)
@@ -106,16 +113,12 @@ Examples:
...
]
<a id="jc.parsers.airport_s.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -123,14 +126,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: darwin
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.arp"></a>
# jc.parsers.arp
jc - JSON CLI output utility `arp` command output parser
jc - JSON Convert `arp` command output parser
Supports `arp` and `arp -a` output.
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('arp', arp_command_output)
or
import jc.parsers.arp
result = jc.parsers.arp.parse(arp_command_output)
@@ -115,16 +122,12 @@ Examples:
}
]
<a id="jc.parsers.arp.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -132,14 +135,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, aix, freebsd, darwin
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.blkid"></a>
# jc.parsers.blkid
jc - JSON CLI output utility `blkid` command output parser
jc - JSON Convert `blkid` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('blkid', blkid_command_output)
or
import jc.parsers.blkid
result = jc.parsers.blkid.parse(blkid_command_output)
@@ -83,7 +90,7 @@ Examples:
{
"id_fs_uuid": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
"id_fs_uuid_enc": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
"id_fs_version": "LVM2\x20001",
"id_fs_version": "LVM2\\x20001",
"id_fs_type": "LVM2_member",
"id_fs_usage": "raid",
"id_iolimit_minimum_io_size": 512,
@@ -118,16 +125,12 @@ Examples:
}
]
<a id="jc.parsers.blkid.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -135,14 +138,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.cksum"></a>
# jc.parsers.cksum
jc - JSON CLI output utility `cksum` command output parser
jc - JSON Convert `cksum` command output parser
This parser works with the following checksum calculation utilities:
- `sum`
@@ -17,6 +19,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('cksum', cksum_command_output)
or
import jc.parsers.cksum
result = jc.parsers.cksum.parse(cksum_command_output)
@@ -52,16 +59,12 @@ Examples:
...
]
<a id="jc.parsers.cksum.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -69,14 +72,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,10 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.crontab"></a>
# jc.parsers.crontab
jc - JSON CLI output utility `crontab -l` command output and crontab file parser
jc - JSON Convert `crontab -l` command output and crontab
file parser
Supports `crontab -l` command output and crontab files.
@@ -15,6 +18,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('crontab', crontab_output)
or
import jc.parsers.crontab
result = jc.parsers.crontab.parse(crontab_output)
@@ -170,16 +178,12 @@ Examples:
]
}
<a id="jc.parsers.crontab.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -187,14 +191,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,13 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.crontab_u"></a>
# jc.parsers.crontab_u
jc - JSON CLI output utility `crontab -l` command output and crontab file parser
# jc.parsers.crontab\_u
This version of the `crontab -l` parser supports output that contains user information for processes.
jc - JSON Convert `crontab -l` command output and crontab
file parser
This version of the `crontab -l` parser supports output that contains user
information for processes.
Usage (cli):
@@ -11,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('crontab_u', crontab_u_output)
or
import jc.parsers.crontab_u
result = jc.parsers.crontab_u.parse(crontab_u_output)
@@ -55,7 +64,7 @@ Examples:
"variables": [
{
"name": "PATH",
"value": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
"value": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sb..."
},
{
"name": "SHELL",
@@ -80,7 +89,7 @@ Examples:
"*"
],
"user": "root",
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )"
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts ..."
},
{
"minute": [
@@ -99,7 +108,7 @@ Examples:
"7"
],
"user": "root",
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )"
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts ..."
},
{
"minute": [
@@ -118,7 +127,7 @@ Examples:
"*"
],
"user": "root",
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )"
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts ..."
}
]
}
@@ -128,7 +137,7 @@ Examples:
"variables": [
{
"name": "PATH",
"value": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
"value": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/..."
},
{
"name": "SHELL",
@@ -143,7 +152,7 @@ Examples:
"month": "*",
"day_of_week": "*",
"user": "root",
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )"
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts ..."
},
{
"minute": "47",
@@ -152,7 +161,7 @@ Examples:
"month": "*",
"day_of_week": "7",
"user": "root",
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )"
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts ..."
},
{
"minute": "52",
@@ -161,21 +170,17 @@ Examples:
"month": "*",
"day_of_week": "*",
"user": "root",
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )"
"command": "test -x /usr/sbin/anacron || ( cd / && run-parts ..."
}
]
}
<a id="jc.parsers.crontab_u.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -183,14 +188,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,13 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.csv"></a>
# jc.parsers.csv
jc - JSON CLI output utility `csv` file parser
The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. The first row of the file must be a header row.
jc - JSON Convert `csv` file parser
The `csv` parser will attempt to automatically detect the delimiter
character. If the delimiter cannot be detected it will default to comma.
The first row of the file must be a header row.
Usage (cli):
@@ -11,12 +15,18 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('csv', csv_output)
or
import jc.parsers.csv
result = jc.parsers.csv.parse(csv_output)
Schema:
csv file converted to a Dictionary: https://docs.python.org/3/library/csv.html
csv file converted to a Dictionary:
https://docs.python.org/3/library/csv.html
[
{
@@ -28,7 +38,7 @@ Schema:
Examples:
$ cat homes.csv
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres", "Taxes"
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres"...
142, 160, 28, 10, 5, 3, 60, 0.28, 3167
175, 180, 18, 8, 4, 1, 12, 0.43, 4033
129, 132, 13, 6, 3, 1, 41, 0.33, 1471
@@ -72,16 +82,12 @@ Examples:
...
]
<a id="jc.parsers.csv.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -89,14 +95,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,13 +1,18 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.csv_s"></a>
# jc.parsers.csv_s
jc - JSON CLI output utility `csv` file streaming parser
# jc.parsers.csv\_s
jc - JSON Convert `csv` file streaming parser
> This streaming parser outputs JSON Lines
The `csv` streaming parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. The first row of the file must be a header row.
The `csv` streaming parser will attempt to automatically detect the
delimiter character. If the delimiter cannot be detected it will default
to comma. The first row of the file must be a header row.
Note: The first 100 rows are read into memory to enable delimiter detection, then the rest of the rows are loaded lazily.
Note: The first 100 rows are read into memory to enable delimiter detection,
then the rest of the rows are loaded lazily.
Usage (cli):
@@ -15,21 +20,34 @@ Usage (cli):
Usage (module):
import jc
# result is an iterable object (generator)
result = jc.parse('csv_s', csv_output.splitlines())
for item in result:
# do something
or
import jc.parsers.csv_s
result = jc.parsers.csv_s.parse(csv_output.splitlines()) # result is an iterable object
# result is an iterable object (generator)
result = jc.parsers.csv_s.parse(csv_output.splitlines())
for item in result:
# do something
Schema:
csv file converted to a Dictionary: https://docs.python.org/3/library/csv.html
csv file converted to a Dictionary:
https://docs.python.org/3/library/csv.html
{
"column_name1": string,
"column_name2": string,
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
# below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # true if successfully parsed, false if error
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
@@ -38,36 +56,35 @@ Schema:
Examples:
$ cat homes.csv
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres", "Taxes"
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres"...
142, 160, 28, 10, 5, 3, 60, 0.28, 3167
175, 180, 18, 8, 4, 1, 12, 0.43, 4033
129, 132, 13, 6, 3, 1, 41, 0.33, 1471
...
$ cat homes.csv | jc --csv-s
{"Sell":"142","List":"160","Living":"28","Rooms":"10","Beds":"5","Baths":"3","Age":"60","Acres":"0.28","Taxes":"3167"}
{"Sell":"175","List":"180","Living":"18","Rooms":"8","Beds":"4","Baths":"1","Age":"12","Acres":"0.43","Taxes":"4033"}
{"Sell":"129","List":"132","Living":"13","Rooms":"6","Beds":"3","Baths":"1","Age":"41","Acres":"0.33","Taxes":"1471"}
{"Sell":"142","List":"160","Living":"28","Rooms":"10","Beds":"5"...}
{"Sell":"175","List":"180","Living":"18","Rooms":"8","Beds":"4"...}
{"Sell":"129","List":"132","Living":"13","Rooms":"6","Beds":"3"...}
...
<a id="jc.parsers.csv_s.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False, ignore_exceptions=False)
@add_jc_meta
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
```
Main text parsing generator function. Returns an iterator object.
Parameters:
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
raw: (boolean) output preprocessed JSON if True
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
@@ -77,9 +94,9 @@ Yields:
Returns:
Iterator object
Iterator object (generator)
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,15 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.date"></a>
# jc.parsers.date
jc - JSON CLI output utility `date` command output parser
The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on)
jc - JSON Convert `date` command output parser
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
The `epoch` calculated timestamp field is naive. (i.e. based on the local
time of the system the parser is run on)
The `epoch_utc` calculated timestamp field is timezone-aware and is only
available if the timezone field is UTC.
Usage (cli):
@@ -17,6 +21,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('date', date_command_output)
or
import jc.parsers.date
result = jc.parsers.date.parse(date_command_output)
@@ -35,15 +44,19 @@ Schema:
"second": integer,
"period": string,
"timezone": string,
"utc_offset": string, # null if timezone field is not UTC
"utc_offset": string, # null if timezone field is not UTC
"day_of_year": integer,
"week_of_year": integer,
"iso": string,
"epoch": integer, # naive timestamp
"epoch_utc": integer, # timezone-aware timestamp. Only available if timezone field is UTC
"timezone_aware": boolean # if true, all fields are correctly based on UTC
"epoch": integer, # [0]
"epoch_utc": integer, # [1]
"timezone_aware": boolean # [2]
}
[0] naive timestamp
[1] timezone-aware timestamp. Only available if timezone field is UTC
[2] if true, all fields are correctly based on UTC
Examples:
$ date | jc --date -p
@@ -69,16 +82,12 @@ Examples:
"timezone_aware": true
}
<a id="jc.parsers.date.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -86,14 +95,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 2.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 2.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.df"></a>
# jc.parsers.df
jc - JSON CLI output utility `df` command output parser
jc - JSON Convert `df` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('df', df_command_output)
or
import jc.parsers.df
result = jc.parsers.df.parse(df_command_output)
@@ -95,16 +102,12 @@ Examples:
...
]
<a id="jc.parsers.df.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -112,14 +115,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.9 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,15 +1,20 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.dig"></a>
# jc.parsers.dig
jc - JSON CLI output utility `dig` command output parser
jc - JSON Convert `dig` command output parser
Options supported:
- `+noall +answer` options are supported in cases where only the answer information is desired.
- `+noall +answer` options are supported in cases where only the answer
information is desired.
- `+axfr` option is supported on its own
The `when_epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
The `when_epoch` calculated timestamp field is naive. (i.e. based on the
local time of the system the parser is run on)
The `when_epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
The `when_epoch_utc` calculated timestamp field is timezone-aware and is
only available if the timezone field is UTC.
Usage (cli):
@@ -21,6 +26,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('dig', dig_command_output)
or
import jc.parsers.dig
result = jc.parsers.dig.parse(dig_command_output)
@@ -93,13 +103,16 @@ Schema:
"query_time": integer, # in msec
"server": string,
"when": string,
"when_epoch": integer, # naive timestamp if when field is parsable, else null
"when_epoch_utc": integer, # timezone aware timestamp availabe for UTC, else null
"when_epoch": integer, # [0]
"when_epoch_utc": integer, # [1]
"rcvd": integer
"size": string
}
]
[0] naive timestamp if "when" field is parsable, else null
[1] timezone aware timestamp availabe for UTC, else null
Examples:
$ dig example.com | jc --dig -p
@@ -314,16 +327,12 @@ Examples:
}
]
<a id="jc.parsers.dig.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -331,14 +340,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, aix, freebsd, darwin, win32, cygwin
Version 2.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 2.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.dir"></a>
# jc.parsers.dir
jc - JSON CLI output utility `dir` command output parser
jc - JSON Convert `dir` command output parser
Options supported:
- `/T timefield`
@@ -9,9 +11,11 @@ Options supported:
- `/C, /-C`
- `/S`
The "Magic" syntax is not supported since the `dir` command is a shell builtin.
The "Magic" syntax is not supported since the `dir` command is a shell
builtin.
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
The `epoch` calculated timestamp field is naive. (i.e. based on the local
time of the system the parser is run on)
Usage (cli):
@@ -19,6 +23,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('dir', dir_command_output)
or
import jc.parsers.dir
result = jc.parsers.dir.parse(dir_command_output)
@@ -46,7 +55,7 @@ Examples:
"dir": true,
"size": null,
"filename": ".",
"parent": "C:\Program Files\Internet Explorer",
"parent": "C:\\Program Files\\Internet Explorer",
"epoch": 1616624100
},
{
@@ -55,7 +64,7 @@ Examples:
"dir": true,
"size": null,
"filename": "..",
"parent": "C:\Program Files\Internet Explorer",
"parent": "C:\\Program Files\\Internet Explorer",
"epoch": 1616624100
},
{
@@ -64,7 +73,7 @@ Examples:
"dir": true,
"size": null,
"filename": "en-US",
"parent": "C:\Program Files\Internet Explorer",
"parent": "C:\\Program Files\\Internet Explorer",
"epoch": 1575715740
},
{
@@ -73,7 +82,7 @@ Examples:
"dir": false,
"size": 54784,
"filename": "ExtExport.exe",
"parent": "C:\Program Files\Internet Explorer",
"parent": "C:\\Program Files\\Internet Explorer",
"epoch": 1575713340
},
...
@@ -87,7 +96,7 @@ Examples:
"dir": true,
"size": null,
"filename": ".",
"parent": "C:\Program Files\Internet Explorer"
"parent": "C:\\Program Files\\Internet Explorer"
},
{
"date": "03/24/2021",
@@ -95,7 +104,7 @@ Examples:
"dir": true,
"size": null,
"filename": "..",
"parent": "C:\Program Files\Internet Explorer"
"parent": "C:\\Program Files\\Internet Explorer"
},
{
"date": "12/07/2019",
@@ -103,7 +112,7 @@ Examples:
"dir": true,
"size": null,
"filename": "en-US",
"parent": "C:\Program Files\Internet Explorer"
"parent": "C:\\Program Files\\Internet Explorer"
},
{
"date": "12/07/2019",
@@ -111,21 +120,17 @@ Examples:
"dir": false,
"size": "54,784",
"filename": "ExtExport.exe",
"parent": "C:\Program Files\Internet Explorer"
"parent": "C:\\Program Files\\Internet Explorer"
},
...
]
<a id="jc.parsers.dir.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -133,14 +138,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: win32
Version 1.4 by Rasheed Elsaleh (rasheed@rebelliondefense.com)
Version 1.5 by Rasheed Elsaleh (rasheed@rebelliondefense.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.dmidecode"></a>
# jc.parsers.dmidecode
jc - JSON CLI output utility `dmidecode` command output parser
jc - JSON Convert `dmidecode` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('dmidecode', dmidecode_command_output)
or
import jc.parsers.dmidecode
result = jc.parsers.dmidecode.parse(dmidecode_command_output)
@@ -24,7 +31,7 @@ Schema:
"type": integer,
"bytes": integer,
"description": string,
"values": { (null if empty)
"values": { # null if empty
"lowercase_no_spaces_keys": string,
"multiline_key_values": [
string,
@@ -123,16 +130,12 @@ Examples:
...
]
<a id="jc.parsers.dmidecode.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -140,14 +143,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,12 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.dpkg_l"></a>
# jc.parsers.dpkg_l
jc - JSON CLI output utility `dpkg -l` command output parser
# jc.parsers.dpkg\_l
Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example:
jc - JSON Convert `dpkg -l` command output parser
Set the `COLUMNS` environment variable to a large value to avoid field
truncation. For example:
$ COLUMNS=500 dpkg -l | jc --dpkg-l
@@ -17,6 +20,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('dpkg_l', dpkg_command_output)
or
import jc.parsers.dpkg_l
result = jc.parsers.dpkg_l.parse(dpkg_command_output)
@@ -72,7 +80,7 @@ Examples:
"name": "acpid",
"version": "1:2.0.28-1ubuntu1",
"architecture": "amd64",
"description": "Advanced Configuration and Power Interface event daemon",
"description": "Advanced Configuration and Power Interface...",
"desired": "remove",
"status": "half installed"
},
@@ -116,7 +124,7 @@ Examples:
"name": "acpid",
"version": "1:2.0.28-1ubuntu1",
"architecture": "amd64",
"description": "Advanced Configuration and Power Interface event daemon"
"description": "Advanced Configuration and Power Interface..."
},
{
"codes": "pn",
@@ -128,16 +136,12 @@ Examples:
...
]
<a id="jc.parsers.dpkg_l.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -145,14 +149,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.du"></a>
# jc.parsers.du
jc - JSON CLI output utility `du` command output parser
jc - JSON Convert `du` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('du', du_command_output)
or
import jc.parsers.du
result = jc.parsers.du.parse(du_command_output)
@@ -35,23 +42,23 @@ Examples:
},
{
"size": 56,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/_CodeSignature"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": 0,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local/standalone"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": 0,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": 0,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": 1008,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/dfu"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
...
]
@@ -64,37 +71,33 @@ Examples:
},
{
"size": "56",
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/_CodeSignature"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": "0",
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local/standalone"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": "0",
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": "0",
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
{
"size": "1008",
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/dfu"
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/..."
},
...
]
<a id="jc.parsers.du.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -102,14 +105,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,14 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.env"></a>
# jc.parsers.env
jc - JSON CLI output utility `env` and `printenv` command output parser
This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
jc - JSON Convert `env` and `printenv` command output parser
This parser will output a list of dictionaries each containing `name` and
`value` keys. If you would like a simple dictionary output, then use the
`-r` command-line option or the `raw=True` argument in the `parse()`
function.
Usage (cli):
@@ -15,6 +20,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('env', env_command_output)
or
import jc.parsers.env
result = jc.parsers.env.parse(env_command_output)
@@ -67,16 +77,12 @@ Examples:
"_": "/usr/bin/env"
}
<a id="jc.parsers.env.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -84,7 +90,7 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
@@ -92,7 +98,7 @@ Returns:
Dictionary of raw structured data or
List of Dictionaries of processed structured data
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.file"></a>
# jc.parsers.file
jc - JSON CLI output utility `file` command output parser
jc - JSON Convert `file` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('file', file_command_output)
or
import jc.parsers.file
result = jc.parsers.file.parse(file_command_output)
@@ -21,7 +28,7 @@ Schema:
[
{
"filename": string,
"type ": string
"type": string
}
]
@@ -51,25 +58,21 @@ Examples:
},
{
"filename": "cd_catalog.xml",
"type": "XML 1.0 document text, ASCII text, with CRLF line terminators"
"type": "XML 1.0 document text, ASCII text, with CRLF line ..."
},
{
"filename": "centosserial.sh",
"type": "Bourne-Again shell script text executable, UTF-8 Unicode text"
"type": "Bourne-Again shell script text executable, UTF-8 ..."
},
...
]
<a id="jc.parsers.file.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -77,14 +80,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, aix, freebsd, darwin
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.finger"></a>
# jc.parsers.finger
jc - JSON CLI output utility `finger` command output parser
jc - JSON Convert `finger` command output parser
Supports `-s` output option. Does not support the `-l` detail option.
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('finger', finger_command_output)
or
import jc.parsers.finger
result = jc.parsers.finger.parse(finger_command_output)
@@ -88,16 +95,12 @@ Examples:
...
]
<a id="jc.parsers.finger.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -105,14 +108,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, freebsd
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.free"></a>
# jc.parsers.free
jc - JSON CLI output utility `free` command output parser
jc - JSON Convert `free` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('free', free_command_output)
or
import jc.parsers.free
result = jc.parsers.free.parse(free_command_output)
@@ -70,16 +77,12 @@ Examples:
}
]
<a id="jc.parsers.free.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -87,14 +90,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.fstab"></a>
# jc.parsers.fstab
jc - JSON CLI output utility `fstab` file parser
jc - JSON Convert `fstab` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('fstab', fstab_command_output)
or
import jc.parsers.fstab
result = jc.parsers.fstab.parse(fstab_command_output)
@@ -83,16 +90,12 @@ Examples:
}
]
<a id="jc.parsers.fstab.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -100,14 +103,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.group"></a>
# jc.parsers.group
jc - JSON CLI output utility `/etc/group` file parser
jc - JSON Convert `/etc/group` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('group', group_file_output)
or
import jc.parsers.group
result = jc.parsers.group.parse(group_file_output)
@@ -107,16 +114,12 @@ Examples:
...
]
<a id="jc.parsers.group.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -124,14 +127,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.gshadow"></a>
# jc.parsers.gshadow
jc - JSON CLI output utility `/etc/gshadow` file parser
jc - JSON Convert `/etc/gshadow` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('gshadow', gshadow_file_output)
or
import jc.parsers.gshadow
result = jc.parsers.gshadow.parse(gshadow_file_output)
@@ -75,16 +82,12 @@ Examples:
...
]
<a id="jc.parsers.gshadow.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -92,14 +95,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, aix, freebsd
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.hash"></a>
# jc.parsers.hash
jc - JSON CLI output utility `hash` command output parser
jc - JSON Convert `hash` command output parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('hash', hash_command_output)
or
import jc.parsers.hash
result = jc.parsers.hash.parse(hash_command_output)
@@ -35,16 +42,12 @@ Examples:
}
]
<a id="jc.parsers.hash.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -52,14 +55,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.hashsum"></a>
# jc.parsers.hashsum
jc - JSON CLI output utility `hash sum` command output parser
jc - JSON Convert `hash sum` command output parser
This parser works with the following hash calculation utilities:
- `md5`
@@ -23,6 +25,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('hashsum', md5sum_command_output)
or
import jc.parsers.hashsum
result = jc.parsers.hashsum.parse(md5sum_command_output)
@@ -66,16 +73,12 @@ Examples:
...
]
<a id="jc.parsers.hashsum.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -83,14 +86,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.hciconfig"></a>
# jc.parsers.hciconfig
jc - JSON CLI output utility `hciconfig` command output parser
jc - JSON Convert `hciconfig` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('hciconfig', hciconfig_command_output)
or
import jc.parsers.hciconfig
result = jc.parsers.hciconfig.parse(hciconfig_command_output)
@@ -315,16 +322,12 @@ Examples:
}
]
<a id="jc.parsers.hciconfig.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -332,14 +335,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,17 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.history"></a>
# jc.parsers.history
jc - JSON CLI output utility `history` command output parser
This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
jc - JSON Convert `history` command output parser
The "Magic" syntax is not supported since the `history` command is a shell builtin.
This parser will output a list of dictionaries each containing `line` and
`command` keys. If you would like a simple dictionary output, then use the
`-r` command-line option or the `raw=True` argument in the `parse()`
function.
The "Magic" syntax is not supported since the `history` command is a shell
builtin.
Usage (cli):
@@ -13,6 +19,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('history', history_command_output)
or
import jc.parsers.history
result = jc.parsers.history.parse(history_command_output)
@@ -39,7 +50,7 @@ Examples:
},
{
"line": 120,
"command": "echo "hello""
"command": "echo \"hello\""
},
{
"line": 121,
@@ -52,21 +63,17 @@ Examples:
{
"118": "sleep 100",
"119": "ls /bin",
"120": "echo "hello"",
"120": "echo \"hello\"",
"121": "docker images",
...
}
<a id="jc.parsers.history.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -74,7 +81,7 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
@@ -82,7 +89,7 @@ Returns:
Dictionary of raw structured data or
List of Dictionaries of processed structured data
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.hosts"></a>
# jc.parsers.hosts
jc - JSON CLI output utility `/etc/hosts` file parser
jc - JSON Convert `/etc/hosts` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('hosts', hosts_file_output)
or
import jc.parsers.hosts
result = jc.parsers.hosts.parse(hosts_file_output)
@@ -72,16 +79,12 @@ Examples:
}
]
<a id="jc.parsers.hosts.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -89,14 +92,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.id"></a>
# jc.parsers.id
jc - JSON CLI output utility `id` command output parser
jc - JSON Convert `id` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('id', id_command_output)
or
import jc.parsers.id
result = jc.parsers.id.parse(id_command_output)
@@ -103,16 +110,12 @@ Examples:
}
}
<a id="jc.parsers.id.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -120,14 +123,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ifconfig"></a>
# jc.parsers.ifconfig
jc - JSON CLI output utility `ifconfig` command output parser
jc - JSON Convert `ifconfig` command output parser
Note: No `ifconfig` options are supported.
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ifconfig', ifconfig_command_output)
or
import jc.parsers.ifconfig
result = jc.parsers.ifconfig.parse(ifconfig_command_output)
@@ -184,16 +191,12 @@ Examples:
}
]
<a id="jc.parsers.ifconfig.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -201,14 +204,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, aix, freebsd, darwin
Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,17 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ini"></a>
# jc.parsers.ini
jc - JSON CLI output utility `INI` file parser
Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
jc - JSON Convert `INI` file parser
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
Parses standard `INI` files and files containing simple key/value pairs.
Delimiter can be `=` or `:`. Missing values are supported. Comment prefix
can be `#` or `;`. Comments must be on their own line.
Note: Values starting and ending with quotation marks will have the marks
removed. If you would like to keep the quotation marks, use the `-r`
command-line argument or the `raw=True` argument in `parse()`.
Usage (cli):
@@ -13,16 +19,18 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ini', ini_file_output)
or
import jc.parsers.ini
result = jc.parsers.ini.parse(ini_file_output)
Schema:
ini or key/value document converted to a dictionary - see configparser standard
library documentation for more details.
Note: Values starting and ending with quotation marks will have the marks removed.
If you would like to keep the quotation marks, use the -r or raw=True argument.
ini or key/value document converted to a dictionary - see the
configparser standard library documentation for more details.
{
"key1": string,
@@ -63,16 +71,12 @@ Examples:
}
}
<a id="jc.parsers.ini.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -80,14 +84,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary representing the ini file
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.iostat"></a>
# jc.parsers.iostat
jc - JSON CLI output utility `iostat` command output parser
jc - JSON Convert `iostat` command output parser
Note: `iostat` version 11 and higher include a JSON output option
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('iostat', iostat_command_output)
or
import jc.parsers.iostat
result = jc.parsers.iostat.parse(iostat_command_output)
@@ -157,16 +164,12 @@ Examples:
}
]
<a id="jc.parsers.iostat.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -174,14 +177,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.iostat_s"></a>
# jc.parsers.iostat_s
jc - JSON CLI output utility `iostat` command output streaming parser
# jc.parsers.iostat\_s
jc - JSON Convert `iostat` command output streaming parser
> This streaming parser outputs JSON Lines
@@ -13,8 +15,17 @@ Usage (cli):
Usage (module):
import jc
# result is an iterable object (generator)
result = jc.parse('iostat_s', iostat_command_output.splitlines())
for item in result:
# do something
or
import jc.parsers.iostat_s
result = jc.parsers.iostat_s.parse(iostat_command_output.splitlines()) # result is an iterable object
# result is an iterable object (generator)
result = jc.parsers.iostat_s.parse(iostat_command_output.splitlines())
for item in result:
# do something
@@ -71,9 +82,12 @@ Schema:
"percent_util": float,
"percent_rrqm": float,
"percent_wrqm": float,
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # true if successfully parsed, false if error
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
@@ -82,33 +96,32 @@ Schema:
Examples:
$ iostat | jc --iostat-s
{"percent_user":0.14,"percent_nice":0.0,"percent_system":0.16,"percent_iowait":0.0,"percent_steal":0.0,"percent_idle":99.7,"type":"cpu"}
{"device":"sda","tps":0.24,"kb_read_s":5.28,"kb_wrtn_s":1.1,"kb_read":203305,"kb_wrtn":42368,"type":"device"}
{"percent_user":0.14,"percent_nice":0.0,"percent_system":0.16,...}
{"device":"sda","tps":0.24,"kb_read_s":5.28,"kb_wrtn_s":1.1...}
...
$ iostat | jc --iostat-s -r
{"percent_user":"0.14","percent_nice":"0.00","percent_system":"0.16","percent_iowait":"0.00","percent_steal":"0.00","percent_idle":"99.70","type":"cpu"}
{"device":"sda","tps":"0.24","kb_read_s":"5.28","kb_wrtn_s":"1.10","kb_read":"203305","kb_wrtn":"42368","type":"device"}
{"percent_user":"0.14","percent_nice":"0.00","percent_system":"0.16"...}
{"device":"sda","tps":"0.24","kb_read_s":"5.28","kb_wrtn_s":"1.10"...}
...
<a id="jc.parsers.iostat_s.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False, ignore_exceptions=False)
@add_jc_meta
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
```
Main text parsing generator function. Returns an iterator object.
Parameters:
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
raw: (boolean) output preprocessed JSON if True
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
@@ -118,9 +131,9 @@ Yields:
Returns:
Iterator object
Iterator object (generator)
## Parser Information
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.iptables"></a>
# jc.parsers.iptables
jc - JSON CLI output utility `ipables` command output parser
jc - JSON Convert `iptables` command output parser
Supports `-vLn` and `--line-numbers` for all tables.
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('iptables', iptables_command_output)
or
import jc.parsers.iptables
result = jc.parsers.iptables.parse(iptables_command_output)
@@ -161,16 +168,12 @@ Examples:
...
]
<a id="jc.parsers.iptables.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -178,14 +181,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,12 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.iw_scan"></a>
# jc.parsers.iw_scan
jc - JSON CLI output utility `iw dev <device> scan` command output parser
# jc.parsers.iw\_scan
This parser is considered beta quality. Not all fields are parsed and there are not enough samples to test.
jc - JSON Convert `iw dev <device> scan` command output parser
This parser is considered beta quality. Not all fields are parsed and there
are not enough samples to test.
Usage (cli):
@@ -15,14 +18,19 @@ Usage (cli):
Usage (module):
import jc.parsers.iw-scan
result = jc.parsers.iw-scan.parse(iw-scan_command_output)
import jc
result = jc.parse('iw_scan', iw_scan_command_output)
or
import jc.parsers.iw_scan
result = jc.parsers.iw_scan.parse(iw_scan_command_output)
Schema:
[
{
"foo": string/integer/float, # best guess based on value
"foo": string/integer/float, # best guess based on value
"bar": string/integer/float,
"baz": string/integer/float
}
@@ -118,16 +126,12 @@ Examples:
...
]
<a id="jc.parsers.iw_scan.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -135,14 +139,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 0.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.jar_manifest"></a>
# jc.parsers.jar_manifest
jc - JSON CLI output utility `MANIFEST.MF` file parser
# jc.parsers.jar\_manifest
jc - JSON Convert `MANIFEST.MF` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('jar_manifest', jar_manifest_file_output)
or
import jc.parsers.jar_manifest
result = jc.parsers.jar_manifest.parse(jar_manifest_file_output)
@@ -24,15 +31,16 @@ Schema:
Examples:
$ cat MANIFEST.MF | jc --jar-manifest -p
$ unzip -c apache-log4j-2.16.0-bin/log4j-core-2.16.0.jar META-INF/MANIFEST.MF | jc --jar-manifest -p
$ unzip -c 'apache-log4j-2.16.0-bin/*.jar' META-INF/MANIFEST.MF | jc --jar-manifest -p
$ unzip -c log4j-core-2.16.0.jar META-INF/MANIFEST.MF | \\
jc --jar-manifest -p
$ unzip -c 'apache-log4j-2.16.0-bin/*.jar' META-INF/MANIFEST.MF | \\
jc --jar-manifest -p
$ cat MANIFEST.MF | jc --jar-manifest -p
[
{
"Import_Package": "com.conversantmedia.util.concurrent;resolution:=optional,com.fasterxml.jackson.annotation;version="[2.12,3)";resolution:=optional,com.fasterxml.jackson.core;version="[2.12,3)";resolution:=optional,com.fasterxml.jackson.core.type;version="[2.12,3)";resolution:=optional,com.fasterxml.jackson.cor...",
"Export_Package": "org.apache.logging.log4j.core;uses:="org.apache.logging.log4j,org.apache.logging.log4j.core.config,org.apache.logging.log4j.core.impl,org.apache.logging.log4j.core.layout,org.apache.logging.log4j.core.time,org.apache.logging.log4j.message,org.apache.logging.log4j.spi,org.apache.logging.log4j.status...",
"Import_Package": "com.conversantmedia.util.concurrent;resoluti...",
"Export_Package": "org.apache.logging.log4j.core;uses:=\"org.ap...",
"Manifest_Version": "1.0",
"Bundle_License": "https://www.apache.org/licenses/LICENSE-2.0.txt",
"Bundle_SymbolicName": "org.apache.logging.log4j.core",
@@ -45,28 +53,28 @@ Examples:
}
]
$ unzip -c 'apache-log4j-2.16.0-bin/*.jar' META-INF/MANIFEST.MF | jc --jar-manifest -p
$ unzip -c 'apache-log4j-2.16.0-bin/*.jar' META-INF/MANIFEST.MF | \\
jc --jar-manifest -p
[
...
{
"Archive": "apache-log4j-2.16.0-bin/log4j-spring-boot-2.16.0-sources.jar",
"Archive": "apache-log4j-2.16.0-bin/log4j-spring-boot-2.16.0-so...",
"Manifest_Version": "1.0",
"Built_By": "matt",
"Created_By": "Apache Maven 3.8.4",
"Build_Jdk": "1.8.0_312"
},
{
"Archive": "apache-log4j-2.16.0-bin/log4j-spring-boot-2.16.0-javadoc.jar",
"Archive": "apache-log4j-2.16.0-bin/log4j-spring-boot-2.16.0-ja...",
"Manifest_Version": "1.0",
"Built_By": "matt",
"Created_By": "Apache Maven 3.8.4",
"Build_Jdk": "1.8.0_312"
},
{
"Bundle_SymbolicName": "org.apache.logging.log4j.spring-cloud-config-client.logging.log4j.core.util;version="[2.16,3)",org.springframework.boot.autoconfigure.condition,org.springframework.cloud.context.environment,org.springframework.context,org.springframework.stereotype",
"Export_Package": "org.apache.logging.log4j.spring.cloud.config.controller;version="2.16.0"ient",
"Archive": "apache-log4j-2.16.0-bin/log4j-spring-cloud-config-client-2.16.0.jar",
"Bundle_SymbolicName": "org.apache.logging.log4j.spring-cloud-c...",
"Export_Package": "org.apache.logging.log4j.spring.cloud.config...",
"Archive": "apache-log4j-2.16.0-bin/log4j-spring-cloud-config-c...",
"Manifest_Version": "1.0",
"Bundle_License": "https://www.apache.org/licenses/LICENSE-2.0.txt",
...
@@ -74,16 +82,12 @@ Examples:
...
]
<a id="jc.parsers.jar_manifest.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -91,14 +95,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 0.01 by Matt J (https://github.com/listuser)

View File

@@ -1,11 +1,14 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.jobs"></a>
# jc.parsers.jobs
jc - JSON CLI output utility `jobs` command output parser
jc - JSON Convert `jobs` command output parser
Also supports the `-l` option.
The "Magic" syntax is not supported since the `jobs` command is a shell builtin.
The "Magic" syntax is not supported since the `jobs` command is a shell
builtin.
Usage (cli):
@@ -13,6 +16,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('jobs', jobs_command_output)
or
import jc.parsers.jobs
result = jc.parsers.jobs.parse(jobs_command_output)
@@ -90,16 +98,12 @@ Example:
}
]
<a id="jc.parsers.jobs.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -107,14 +111,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,17 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.kv"></a>
# jc.parsers.kv
jc - JSON CLI output utility `Key/Value` file parser
Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
jc - JSON Convert `Key/Value` file parser
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
Supports files containing simple key/value pairs. Delimiter can be `=` or
`:`. Missing values are supported. Comment prefix can be `#` or `;`.
Comments must be on their own line.
Note: Values starting and ending with quotation marks will have the marks
removed. If you would like to keep the quotation marks, use the `-r`
command-line argument or the `raw=True` argument in `parse()`.
Usage (cli):
@@ -13,12 +19,18 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('kv', kv_file_output)
or
import jc.parsers.kv
result = jc.parsers.kv.parse(kv_file_output)
Schema:
key/value document converted to a dictionary - see configparser standard library documentation for more details.
key/value document converted to a dictionary - see the
configparser standard library documentation for more details.
{
"key1": string,
@@ -46,16 +58,12 @@ Examples:
"occupation": "Engineer"
}
<a id="jc.parsers.kv.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -65,14 +73,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary representing the key/value file
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,15 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.last"></a>
# jc.parsers.last
jc - JSON CLI output utility `last` and `lastb` command output parser
jc - JSON Convert `last` and `lastb` command output parser
Supports `-w` and `-F` options.
Calculated epoch time fields are naive (i.e. based on the local time of the system the parser is run on) since there is no timezone information in the `last` command output.
Calculated epoch time fields are naive (i.e. based on the local time of the
system the parser is run on) since there is no timezone information in the
`last` command output.
Usage (cli):
@@ -17,6 +21,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('last', last_command_output)
or
import jc.parsers.last
result = jc.parsers.last.parse(last_command_output)
@@ -30,9 +39,9 @@ Schema:
"login": string,
"logout": string,
"duration": string,
"login_epoch": integer, # (naive) available with last -F option
"logout_epoch": integer, # (naive) available with last -F option
"duration_seconds": integer # available with last -F option
"login_epoch": integer, # (naive) available w/last -F option
"logout_epoch": integer, # (naive) available w/last -F option
"duration_seconds": integer # available w/last -F option
}
]
@@ -100,17 +109,12 @@ Examples:
...
]
<a id="jc.parsers.last.parse"></a>
### parse
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -118,14 +122,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,17 +1,25 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ls"></a>
# jc.parsers.ls
jc - JSON CLI output utility `ls` and `vdir` command output parser
jc - JSON Convert `ls` and `vdir` command output parser
Options supported:
- `lbaR1`
- `--time-style=full-iso`
Note: The `-1`, `-l`, or `-b` option of `ls` should be used to correctly parse filenames that include newline characters. Since `ls` does not encode newlines in filenames when outputting to a pipe it will cause `jc` to see multiple files instead of a single file if `-1`, `-l`, or `-b` is not used. Alternatively, `vdir` can be used, which is the same as running `ls -lb`.
Note: The `-1`, `-l`, or `-b` option of `ls` should be used to correctly
parse filenames that include newline characters. Since `ls` does not encode
newlines in filenames when outputting to a pipe it will cause `jc` to see
multiple files instead of a single file if `-1`, `-l`, or `-b` is not used.
Alternatively, `vdir` can be used, which is the same as running `ls -lb`.
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
The `epoch` calculated timestamp field is naive. (i.e. based on the local
time of the system the parser is run on)
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
The `epoch_utc` calculated timestamp field is timezone-aware and is only
available if the timezone field is UTC.
Usage (cli):
@@ -23,6 +31,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ls', ls_command_output)
or
import jc.parsers.ls
result = jc.parsers.ls.parse(ls_command_output)
@@ -38,11 +51,15 @@ Schema:
"group": string,
"size": integer,
"date": string,
"epoch": integer, # naive timestamp if date field exists and can be converted
"epoch_utc": integer # timezone aware timestamp if date field is in UTC and can be converted
"epoch": integer, # [0]
"epoch_utc": integer # [1]
}
]
[0] naive timestamp if date field exists and can be converted.
[1] timezone aware timestamp if date field is in UTC and can
be converted.
Examples:
$ ls /usr/bin | jc --ls -p
@@ -104,16 +121,12 @@ Examples:
...
]
<a id="jc.parsers.ls.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -121,14 +134,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,17 +1,24 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ls_s"></a>
# jc.parsers.ls_s
jc - JSON CLI output utility `ls` and `vdir` command output streaming parser
# jc.parsers.ls\_s
jc - JSON Convert `ls` and `vdir` command output streaming
parser
> This streaming parser outputs JSON Lines
Requires the `-l` option to be used on `ls`. If there are newline characters in the filename, then make sure to use the `-b` option on `ls`.
Requires the `-l` option to be used on `ls`. If there are newline characters
in the filename, then make sure to use the `-b` option on `ls`.
The `jc` `-qq` option can be used to ignore parsing errors. (e.g. filenames with newline characters, but `-b` was not used)
The `jc` `-qq` option can be used to ignore parsing errors. (e.g. filenames
with newline characters, but `-b` was not used)
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
The `epoch` calculated timestamp field is naive (i.e. based on the local
time of the system the parser is run on)
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
The `epoch_utc` calculated timestamp field is timezone-aware and is only
available if the timezone field is UTC.
Usage (cli):
@@ -19,8 +26,17 @@ Usage (cli):
Usage (module):
import jc
# result is an iterable object (generator)
result = jc.parse('ls_s', ls_command_output.splitlines())
for item in result:
# do something
or
import jc.parsers.ls_s
result = jc.parsers.ls_s.parse(ls_command_output.splitlines()) # result is an iterable object
# result is an iterable object (generator)
result = jc.parsers.ls_s.parse(ls_command_output.splitlines())
for item in result:
# do something
@@ -35,48 +51,54 @@ Schema:
"group": string,
"size": integer,
"date": string,
"epoch": integer, # naive timestamp if date field exists and can be converted
"epoch_utc": integer, # timezone aware timestamp if date field is in UTC and can be converted
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
"epoch": integer, # [0]
"epoch_utc": integer, # [1]
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # true if successfully parsed, false if error
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
}
[0] naive timestamp if date field exists and can be converted.
[1] timezone aware timestamp if date field is in UTC and can
be converted
Examples:
$ ls -l /usr/bin | jc --ls-s
{"filename":"2to3-","flags":"-rwxr-xr-x","links":4,"owner":"root","group":"wheel","size":925,"date":"Feb 22 2019"}
{"filename":"2to3-2.7","link_to":"../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/2to3-2.7","flags":"lrwxr-xr-x","links":1,"owner":"root","group":"wheel","size":74,"date":"May 4 2019"}
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":1,"owner":"root","group":"wheel","size":55152,"date":"May 3 2019"}
{"filename":"2to3-","flags":"-rwxr-xr-x","links":4,"owner":"root","...}
{"filename":"2to3-2.7","link_to":"../../System/Library/Frameworks/P...}
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":1,...}
...
$ ls -l /usr/bin | jc --ls-s -r
{"filename":"2to3-","flags":"-rwxr-xr-x","links":"4","owner":"root","group":"wheel","size":"925","date":"Feb 22 2019"}
{"filename":"2to3-2.7","link_to":"../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/2to3-2.7","flags":"lrwxr-xr-x","links":"1","owner":"root","group":"wheel","size":"74","date":"May 4 2019"}
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":"1","owner":"root","group":"wheel","size":"55152","date":"May 3 2019"}
{"filename":"2to3-","flags":"-rwxr-xr-x","links":"4","owner":"roo"..."}
{"filename":"2to3-2.7","link_to":"../../System/Library/Frameworks/P...}
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":"1...}
...
<a id="jc.parsers.ls_s.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False, ignore_exceptions=False)
@add_jc_meta
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
```
Main text parsing generator function. Returns an iterator object.
Parameters:
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
raw: (boolean) output preprocessed JSON if True
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
@@ -86,9 +108,9 @@ Yields:
Returns:
Iterator object
Iterator object (generator)
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 0.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.lsblk"></a>
# jc.parsers.lsblk
jc - JSON CLI output utility `lsblk` command output parser
jc - JSON Convert `lsblk` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('lsblk', lsblk_command_output)
or
import jc.parsers.lsblk
result = jc.parsers.lsblk.parse(lsblk_command_output)
@@ -88,7 +95,10 @@ Examples:
...
]
$ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p
$ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,\\
STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,\\
SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,\\
PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p
[
{
"name": "sda",
@@ -177,7 +187,10 @@ Examples:
...
]
$ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p -r
$ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,\\
STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,\\
SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,\\
PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p -r
[
{
"name": "sda",
@@ -266,16 +279,12 @@ Examples:
...
]
<a id="jc.parsers.lsblk.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -283,14 +292,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.lsmod"></a>
# jc.parsers.lsmod
jc - JSON CLI output utility `lsmod` command output parser
jc - JSON Convert `lsmod` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('lsmod', lsmod_command_output)
or
import jc.parsers.lsmod
result = jc.parsers.lsmod.parse(lsmod_command_output)
@@ -123,16 +130,12 @@ Examples:
...
]
<a id="jc.parsers.lsmod.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -140,14 +143,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.lsof"></a>
# jc.parsers.lsof
jc - JSON CLI output utility `lsof` command output parser
jc - JSON Convert `lsof` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('lsof', lsof_command_output)
or
import jc.parsers.lsof
result = jc.parsers.lsof.parse(lsof_command_output)
@@ -117,16 +124,12 @@ Examples:
...
]
<a id="jc.parsers.lsof.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -134,14 +137,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.lsusb"></a>
# jc.parsers.lsusb
jc - JSON CLI output utility `lsusb` command output parser
jc - JSON Convert `lsusb` command output parser
Supports the `-v` option or no options.
@@ -15,13 +17,19 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('lsusb', lsusb_command_output)
or
import jc.parsers.lsusb
result = jc.parsers.lsusb.parse(lsusb_command_output)
Schema:
Note: <item> object keynames are assigned directly from the lsusb output.
If there are duplicate <item> names in a section, only the last one is converted.
Note: <item> object keynames are assigned directly from the lsusb
output. If there are duplicate <item> names in a section, only the
last one is converted.
[
{
@@ -258,16 +266,12 @@ Examples:
}
]
<a id="jc.parsers.lsusb.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -275,14 +279,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.mount"></a>
# jc.parsers.mount
jc - JSON CLI output utility `mount` command output parser
jc - JSON Convert `mount` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('mount', mount_command_output)
or
import jc.parsers.mount
result = jc.parsers.mount.parse(mount_command_output)
@@ -73,16 +80,12 @@ Example:
...
]
<a id="jc.parsers.mount.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -90,14 +93,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,14 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.netstat"></a>
# jc.parsers.netstat
jc - JSON CLI output utility `netstat` command output parser
jc - JSON Convert `netstat` command output parser
Caveats:
- Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`)
- Use of the `A` option is not supported on OSX when using the `r` option (e.g. `netstat -rA`)
- Use of the `A` option is not supported on OSX when using the `r` option
(e.g. `netstat -rA`)
Usage (cli):
@@ -17,6 +20,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('netstat', netstat_command_output)
or
import jc.parsers.netstat
result = jc.parsers.netstat.parse(netstat_command_output)
@@ -352,16 +360,12 @@ Examples:
}
]
<a id="jc.parsers.netstat.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -369,14 +373,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.12 by Kelly Brazil (kellyjonbrazil@gmail.com)

176
docs/parsers/nmcli.md Normal file
View File

@@ -0,0 +1,176 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.nmcli"></a>
# jc.parsers.nmcli
jc - JSON Convert `nmcli` command output parser
Supports the following `nmcli` subcommands:
- `nmcli general`
- `nmcli general permissions`
- `nmcli connection`
- `nmcli connection show <device_name>`
- `nmcli device`
- `nmcli device show`
- `nmcli device show <device_name>`
Usage (cli):
$ nmcli device show lo | jc --nmcli
or
$ jc nmcli device show lo
Usage (module):
import jc
result = jc.parse('nmcli', nmcli_command_output)
or
import jc.parsers.nmcli
result = jc.parsers.nmcli.parse(nmcli_command_output)
Schema:
Because there are so many options, the schema is not strictly defined.
Integer and Float value conversions are attempted and the original
values are kept if they fail. If you don't want automatic conversion,
then use the -r or raw=True option to disable it.
The structure is flat, for the most part, but there are a couple of
"well-known" keys that are further parsed into objects for convenience.
These are documented below.
[
{
"<key>": string/integer/float, [0]
"dhcp4_option_x": {
"name": string,
"value": string/integer/float,
},
"dhcp6_option_x": {
"name": string,
"value": string/integer/float,
},
"ip4_route_x": {
"dst": string,
"nh": string,
"mt": integer
},
"ip6_route_x": {
"dst": string,
"nh": string,
"mt": integer,
"table": integer
}
}
]
[0] all values of `---` are converted to null
Examples:
$ nmcli connection show ens33 | jc --nmcli -p
[
{
"connection_id": "ens33",
"connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744",
"connection_stable_id": null,
"connection_type": "802-3-ethernet",
"connection_interface_name": "ens33",
"connection_autoconnect": "yes",
...
"ip4_address_1": "192.168.71.180/24",
"ip4_gateway": "192.168.71.2",
"ip4_route_1": {
"dst": "0.0.0.0/0",
"nh": "192.168.71.2",
"mt": 100
},
"ip4_route_2": {
"dst": "192.168.71.0/24",
"nh": "0.0.0.0",
"mt": 100
},
"ip4_dns_1": "192.168.71.2",
"ip4_domain_1": "localdomain",
"dhcp4_option_1": {
"name": "broadcast_address",
"value": "192.168.71.255"
},
...
"ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64",
"ip6_gateway": null,
"ip6_route_1": {
"dst": "fe80::/64",
"nh": "::",
"mt": 100
}
}
]
$ nmcli connection show ens33 | jc --nmcli -p -r
[
{
"connection_id": "ens33",
"connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744",
"connection_stable_id": null,
"connection_type": "802-3-ethernet",
"connection_interface_name": "ens33",
"connection_autoconnect": "yes",
...
"ip4_address_1": "192.168.71.180/24",
"ip4_gateway": "192.168.71.2",
"ip4_route_1": {
"dst": "0.0.0.0/0",
"nh": "192.168.71.2",
"mt": "100"
},
"ip4_route_2": {
"dst": "192.168.71.0/24",
"nh": "0.0.0.0",
"mt": "100"
},
"ip4_dns_1": "192.168.71.2",
"ip4_domain_1": "localdomain",
"dhcp4_option_1": {
"name": "broadcast_address",
"value": "192.168.71.255"
},
...
"ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64",
"ip6_gateway": null,
"ip6_route_1": {
"dst": "fe80::/64",
"nh": "::",
"mt": "100"
}
}
]
<a id="jc.parsers.nmcli.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ntpq"></a>
# jc.parsers.ntpq
jc - JSON CLI output utility `ntpq -p` command output parser
jc - JSON Convert `ntpq -p` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ntpq', ntpq_command_output)
or
import jc.parsers.ntpq
result = jc.parsers.ntpq.parse(ntpq_command_output)
@@ -204,16 +211,12 @@ Examples:
}
]
<a id="jc.parsers.ntpq.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -221,14 +224,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.passwd"></a>
# jc.parsers.passwd
jc - JSON CLI output utility `/etc/passwd` file Parser
jc - JSON Convert `/etc/passwd` file Parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('passwd', passwd_file_output)
or
import jc.parsers.passwd
result = jc.parsers.passwd.parse(passwd_file_output)
@@ -92,16 +99,12 @@ Examples:
...
]
<a id="jc.parsers.passwd.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -109,14 +112,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,13 +1,16 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ping"></a>
# jc.parsers.ping
jc - JSON CLI output utility `ping` command output parser
jc - JSON Convert `ping` command output parser
Supports `ping` and `ping6` output.
Usage (cli):
Note: Use the ping `-c` (count) option, otherwise data will not be piped to `jc`.
Note: Use the ping `-c` (count) option, otherwise data will not be
piped to `jc`.
$ ping -c 3 1.2.3.4 | jc --ping
@@ -17,6 +20,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ping', ping_command_output)
or
import jc.parsers.ping
result = jc.parsers.ping.parse(ping_command_output)
@@ -26,7 +34,7 @@ Schema:
"source_ip": string,
"destination_ip": string,
"data_bytes": integer,
"pattern": string, # (null if not set)
"pattern": string, # null if not set
"destination": string,
"packets_transmitted": integer,
"packets_received": integer,
@@ -38,8 +46,8 @@ Schema:
"round_trip_ms_stddev": float,
"responses": [
{
"type": string, # 'reply', 'timeout', 'unparsable_line', etc. See `_error_type.type_map` for all options
"unparsed_line": string, # only if an 'unparsable_line' type
"type": string, # [0]
"unparsed_line": string, # [1]
"timestamp": float,
"bytes": integer,
"response_ip": string,
@@ -47,21 +55,26 @@ Schema:
"ttl": integer,
"time_ms": float,
"duplicate": boolean,
"vr": integer, # hex value converted to decimal
"hl": integer, # hex value converted to decimal
"tos": integer, # hex value converted to decimal
"len": integer, # hex value converted to decimal
"id": integer, # hex value converted to decimal
"flg": integer, # hex value converted to decimal
"off": integer, # hex value converted to decimal
"pro": integer, # hex value converted to decimal
"cks": ingeger, # hex value converted to decimal
"vr": integer, # [2]
"hl": integer, # [2]
"tos": integer, # [2]
"len": integer, # [2]
"id": integer, # [2]
"flg": integer, # [2]
"off": integer, # [2]
"pro": integer, # [2]
"cks": ingeger, # [2]
"src": string,
"dst": string
}
]
}
[0] 'reply', 'timeout', 'unparsable_line', etc. See
`_error_type.type_map` for all options
[1] only if an 'unparsable_line' type
[2] hex value converted to decimal
Examples:
$ ping -c 3 -p ff cnn.com | jc --ping -p
@@ -154,16 +167,12 @@ Examples:
]
}
<a id="jc.parsers.ping.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -171,14 +180,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ping_s"></a>
# jc.parsers.ping_s
jc - JSON CLI output utility `ping` command output streaming parser
# jc.parsers.ping\_s
jc - JSON Convert `ping` command output streaming parser
> This streaming parser outputs JSON Lines
@@ -11,79 +13,98 @@ Usage (cli):
$ ping | jc --ping-s
> Note: When piping `jc` converted `ping` output to other processes it may appear the output is hanging due to the OS pipe buffers. This is because `ping` output is too small to quickly fill up the buffer. Use the `-u` option to unbuffer the `jc` output if you would like immediate output. See the [readme](https://github.com/kellyjonbrazil/jc/tree/master#unbuffering-output) for more information.
> Note: When piping `jc` converted `ping` output to other processes it may
appear the output is hanging due to the OS pipe buffers. This is because
`ping` output is too small to quickly fill up the buffer. Use the `-u`
option to unbuffer the `jc` output if you would like immediate output.
See the [readme](https://github.com/kellyjonbrazil/jc/tree/master#unbuffering-output)
for more information.
Usage (module):
import jc
# result is an iterable object (generator)
result = jc.parse('ping_s', ping_command_output.splitlines())
for item in result:
# do something
or
import jc.parsers.ping_s
result = jc.parsers.ping_s.parse(ping_command_output.splitlines()) # result is an iterable object
# result is an iterable object (generator)
result = jc.parsers.ping_s.parse(ping_command_output.splitlines())
for item in result:
# do something
Schema:
{
"type": string, # 'reply', 'timeout', 'summary', etc. See `_error_type.type_map` for all options.
"source_ip": string,
"destination_ip": string,
"sent_bytes": integer,
"pattern": string, # (null if not set)
"destination": string,
"timestamp": float,
"response_bytes": integer,
"response_ip": string,
"icmp_seq": integer,
"ttl": integer,
"time_ms": float,
"duplicate": boolean,
"packets_transmitted": integer,
"packets_received": integer,
"packet_loss_percent": float,
"duplicates": integer,
"round_trip_ms_min": float,
"round_trip_ms_avg": float,
"round_trip_ms_max": float,
"round_trip_ms_stddev": float,
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
"type": string, # [0]
"source_ip": string,
"destination_ip": string,
"sent_bytes": integer,
"pattern": string, # (null if not set)
"destination": string,
"timestamp": float,
"response_bytes": integer,
"response_ip": string,
"icmp_seq": integer,
"ttl": integer,
"time_ms": float,
"duplicate": boolean,
"packets_transmitted": integer,
"packets_received": integer,
"packet_loss_percent": float,
"duplicates": integer,
"round_trip_ms_min": float,
"round_trip_ms_avg": float,
"round_trip_ms_max": float,
"round_trip_ms_stddev": float,
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # true if successfully parsed, false if error
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
}
[0] 'reply', 'timeout', 'summary', etc. See `_error_type.type_map`
for all options.
Examples:
$ ping 1.1.1.1 | jc --ping-s
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"pattern":null,"response_bytes":64,"response_ip":"1.1.1.1","icmp_seq":0,"ttl":56,"time_ms":23.703}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"pattern":null,"response_bytes":64,"response_ip":"1.1.1.1","icmp_seq":1,"ttl":56,"time_ms":22.862}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"pattern":null,"response_bytes":64,"response_ip":"1.1.1.1","icmp_seq":2,"ttl":56,"time_ms":22.82}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"patte...}
...
$ ping 1.1.1.1 | jc --ping-s -r
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","pattern":null,"response_bytes":"64","response_ip":"1.1.1.1","icmp_seq":"0","ttl":"56","time_ms":"23.054"}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","pattern":null,"response_bytes":"64","response_ip":"1.1.1.1","icmp_seq":"1","ttl":"56","time_ms":"24.739"}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","pattern":null,"response_bytes":"64","response_ip":"1.1.1.1","icmp_seq":"2","ttl":"56","time_ms":"23.232"}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","patte...}
...
<a id="jc.parsers.ping_s.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False, ignore_exceptions=False)
@add_jc_meta
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
```
Main text parsing generator function. Returns an iterator object.
Parameters:
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
raw: (boolean) output preprocessed JSON if True
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
@@ -93,9 +114,9 @@ Yields:
Returns:
Iterator object
Iterator object (generator)
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 0.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.pip_list"></a>
# jc.parsers.pip_list
jc - JSON CLI output utility `pip-list` command output parser
# jc.parsers.pip\_list
jc - JSON Convert `pip-list` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('pip_list', pip_list_command_output)
or
import jc.parsers.pip_list
result = jc.parsers.pip_list.parse(pip_list_command_output)
@@ -45,16 +52,12 @@ Examples:
...
]
<a id="jc.parsers.pip_list.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -62,14 +65,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.pip_show"></a>
# jc.parsers.pip_show
jc - JSON CLI output utility `pip-show` command output parser
# jc.parsers.pip\_show
jc - JSON Convert `pip-show` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('pip_show', pip_show_command_output)
or
import jc.parsers.pip_show
result = jc.parsers.pip_show.parse(pip_show_command_output)
@@ -63,16 +70,12 @@ Examples:
}
]
<a id="jc.parsers.pip_show.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -80,14 +83,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ps"></a>
# jc.parsers.ps
jc - JSON CLI output utility `ps` command output parser
jc - JSON Convert `ps` command output parser
`ps` options supported:
- `ef`
@@ -17,6 +19,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ps', ps_command_output)
or
import jc.parsers.ps
result = jc.parsers.ps.parse(ps_command_output)
@@ -56,7 +63,7 @@ Examples:
"stime": "Nov01",
"tty": null,
"time": "00:00:11",
"cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
"cmd": "/usr/lib/systemd/systemd --switched-root --system --dese..."
},
{
"uid": "root",
@@ -91,7 +98,7 @@ Examples:
"stime": "Nov01",
"tty": "?",
"time": "00:00:11",
"cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
"cmd": "/usr/lib/systemd/systemd --switched-root --system --dese..."
},
{
"uid": "root",
@@ -129,7 +136,7 @@ Examples:
"stat": "Ss",
"start": "Nov09",
"time": "0:08",
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
"command": "/usr/lib/systemd/systemd --switched-root --system --..."
},
{
"user": "root",
@@ -173,7 +180,7 @@ Examples:
"stat": "Ss",
"start": "Nov09",
"time": "0:08",
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
"command": "/usr/lib/systemd/systemd --switched-root --system --..."
},
{
"user": "root",
@@ -204,16 +211,12 @@ Examples:
...
]
<a id="jc.parsers.ps.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -221,14 +224,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.route"></a>
# jc.parsers.route
jc - JSON CLI output utility `route` command output parser
jc - JSON Convert `route` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('route', route_command_output)
or
import jc.parsers.route
result = jc.parsers.route.parse(route_command_output)
@@ -106,16 +113,12 @@ Examples:
}
]
<a id="jc.parsers.route.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -123,14 +126,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,13 +1,17 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.rpm_qi"></a>
# jc.parsers.rpm_qi
jc - JSON CLI output utility `rpm -qi` command output parser
# jc.parsers.rpm\_qi
jc - JSON Convert `rpm -qi` command output parser
Works with `rpm -qi [package]` or `rpm -qia`.
The `..._epoch` calculated timestamp fields are naive (i.e. based on the local time of the system the parser is run on)
The `..._epoch` calculated timestamp fields are naive. (i.e. based on the
local time of the system the parser is run on)
The `..._epoch_utc` calculated timestamp fields are timezone-aware and is only available if the timezone field is UTC.
The `..._epoch_utc` calculated timestamp fields are timezone-aware and is
only available if the timezone field is UTC.
Usage (cli):
@@ -19,6 +23,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('rpm_qi', rpm_qi_command_output)
or
import jc.parsers.rpm_qi
result = jc.parsers.rpm_qi.parse(rpm_qi_command_output)
@@ -32,16 +41,16 @@ Schema:
"release": string,
"architecture": string,
"install_date": string,
"install_date_epoch": integer, # naive timestamp
"install_date_epoch_utc": integer, # Aware timestamp if timezone is UTC
"install_date_epoch": integer, # [0]
"install_date_epoch_utc": integer, # [1]
"group": string,
"size": integer,
"license": string,
"signature": string,
"source_rpm": string,
"build_date": string,
"build_epoch": integer, # naive timestamp
"build_epoch_utc": integer, # Aware timestamp if timezone is UTC
"build_epoch": integer, # [0]
"build_epoch_utc": integer, # [1]
"build_host": string,
"relocations": string,
"packager": string,
@@ -52,6 +61,9 @@ Schema:
}
]
[0] naive timestamp
[1] Aware timestamp if timezone is UTC
Examples:
$ rpm -qia | jc --rpm-qi -p
@@ -66,7 +78,7 @@ Examples:
"group": "Development/Tools",
"size": 1160660,
"license": "GPLv2+",
"signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5",
"signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ...",
"source_rpm": "make-3.82-24.el7.src.rpm",
"build_date": "Thu 08 Aug 2019 05:47:25 PM PDT",
"build_host": "x86-01.bsys.centos.org",
@@ -74,8 +86,8 @@ Examples:
"packager": "CentOS BuildSystem <http://bugs.centos.org>",
"vendor": "CentOS",
"url": "http://www.gnu.org/software/make/",
"summary": "A GNU tool which simplifies the build process for users",
"description": "A GNU tool for controlling the generation of executables and other...",
"summary": "A GNU tool which simplifies the build process for ...",
"description": "A GNU tool for controlling the generation of ex...",
"build_epoch": 1565311645,
"build_epoch_utc": null,
"install_date_epoch": 1571242902,
@@ -90,7 +102,7 @@ Examples:
"group": "System Environment/Base",
"size": 503608,
"license": "GPLv2+",
"signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ID 24c6a8a7f4a80eb5",
"signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ...",
"source_rpm": "kbd-1.15.5-15.el7.src.rpm",
"build_date": "Tue 30 Oct 2018 03:40:00 PM PDT",
"build_host": "x86-01.bsys.centos.org",
@@ -99,7 +111,7 @@ Examples:
"vendor": "CentOS",
"url": "http://ftp.altlinux.org/pub/people/legion/kbd",
"summary": "Legacy data for kbd package",
"description": "The kbd-legacy package contains original keymaps for kbd package...",
"description": "The kbd-legacy package contains original keymap...",
"build_epoch": 1540939200,
"build_epoch_utc": null,
"install_date_epoch": 1565891588,
@@ -120,7 +132,7 @@ Examples:
"group": "Development/Tools",
"size": "1160660",
"license": "GPLv2+",
"signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5",
"signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ...",
"source_rpm": "make-3.82-24.el7.src.rpm",
"build_date": "Thu 08 Aug 2019 05:47:25 PM PDT",
"build_host": "x86-01.bsys.centos.org",
@@ -128,8 +140,8 @@ Examples:
"packager": "CentOS BuildSystem <http://bugs.centos.org>",
"vendor": "CentOS",
"url": "http://www.gnu.org/software/make/",
"summary": "A GNU tool which simplifies the build process for users",
"description": "A GNU tool for controlling the generation of executables and other..."
"summary": "A GNU tool which simplifies the build process for...",
"description": "A GNU tool for controlling the generation of exe..."
},
{
"name": "kbd-legacy",
@@ -140,7 +152,7 @@ Examples:
"group": "System Environment/Base",
"size": "503608",
"license": "GPLv2+",
"signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ID 24c6a8a7f4a80eb5",
"signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ...",
"source_rpm": "kbd-1.15.5-15.el7.src.rpm",
"build_date": "Tue 30 Oct 2018 03:40:00 PM PDT",
"build_host": "x86-01.bsys.centos.org",
@@ -149,21 +161,17 @@ Examples:
"vendor": "CentOS",
"url": "http://ftp.altlinux.org/pub/people/legion/kbd",
"summary": "Legacy data for kbd package",
"description": "The kbd-legacy package contains original keymaps for kbd package..."
"description": "The kbd-legacy package contains original keymaps..."
},
...
]
<a id="jc.parsers.rpm_qi.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -171,14 +179,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

165
docs/parsers/rsync.md Normal file
View File

@@ -0,0 +1,165 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.rsync"></a>
# jc.parsers.rsync
jc - JSON Convert `rsync` command output parser
Supports the `-i` or `--itemize-changes` options with all levels of
verbosity. This parser will process the STDOUT output or a log file
generated with the `--log-file` option.
Usage (cli):
$ rsync -i -a source/ dest | jc --rsync
or
$ jc rsync -i -a source/ dest
or
$ cat rsync-backup.log | jc --rsync
Usage (module):
import jc
result = jc.parse('rsync', rsync_command_output)
or
import jc.parsers.rsync
result = jc.parsers.rsync.parse(rsync_command_output)
Schema:
[
{
"summary": {
"date": string,
"time": string,
"process": integer,
"sent": integer,
"received": integer,
"total_size": integer,
"matches": integer,
"hash_hits": integer,
"false_alarms": integer,
"data": integer,
"bytes_sec": float,
"speedup": float
},
"files": [
{
"filename": string,
"date": string,
"time": string,
"process": integer,
"metadata": string,
"update_type": string/null, [0]
"file_type": string/null, [1]
"checksum_or_value_different": bool/null,
"size_different": bool/null,
"modification_time_different": bool/null,
"permissions_different": bool/null,
"owner_different": bool/null,
"group_different": bool/null,
"acl_different": bool/null,
"extended_attribute_different": bool/null,
"epoch": integer, [2]
}
]
}
]
[0] 'file sent', 'file received', 'local change or creation',
'hard link', 'not updated', 'message'
[1] 'file', 'directory', 'symlink', 'device', 'special file'
[2] naive timestamp if time and date fields exist and can be converted.
Examples:
$ rsync -i -a source/ dest | jc --rsync -p
[
{
"summary": {
"sent": 1708,
"received": 8209,
"bytes_sec": 19834.0,
"total_size": 235,
"speedup": 0.02
},
"files": [
{
"filename": "./",
"metadata": ".d..t......",
"update_type": "not updated",
"file_type": "directory",
"checksum_or_value_different": false,
"size_different": false,
"modification_time_different": true,
"permissions_different": false,
"owner_different": false,
"group_different": false,
"acl_different": false,
"extended_attribute_different": false
},
...
]
}
]
$ rsync | jc --rsync -p -r
[
{
"summary": {
"sent": "1,708",
"received": "8,209",
"bytes_sec": "19,834.00",
"total_size": "235",
"speedup": "0.02"
},
"files": [
{
"filename": "./",
"metadata": ".d..t......",
"update_type": "not updated",
"file_type": "directory",
"checksum_or_value_different": false,
"size_different": false,
"modification_time_different": true,
"permissions_different": false,
"owner_different": false,
"group_different": false,
"acl_different": false,
"extended_attribute_different": false
},
...
]
}
]
<a id="jc.parsers.rsync.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

130
docs/parsers/rsync_s.md Normal file
View File

@@ -0,0 +1,130 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.rsync_s"></a>
# jc.parsers.rsync\_s
jc - JSON Convert `rsync` command output streaming parser
> This streaming parser outputs JSON Lines
Supports the `-i` or `--itemize-changes` options with all levels of
verbosity. This parser will process the STDOUT output or a log file
generated with the `--log-file` option.
Usage (cli):
$ rsync -i -a source/ dest | jc --rsync-s
or
$ cat rsync-backup.log | jc --rsync-s
Usage (module):
import jc
# result is an iterable object (generator)
result = jc.parse('rsync_s', rsync_command_output.splitlines())
for item in result:
# do something
or
import jc.parsers.rsync_s
# result is an iterable object (generator)
result = jc.parsers.rsync_s.parse(rsync_command_output.splitlines())
for item in result:
# do something
Schema:
{
"type": string, # 'file' or 'summary'
"date": string,
"time": string,
"process": integer,
"sent": integer,
"received": integer,
"total_size": integer,
"matches": integer,
"hash_hits": integer,
"false_alarms": integer,
"data": integer,
"bytes_sec": float,
"speedup": float,
"filename": string,
"date": string,
"time": string,
"process": integer,
"metadata": string,
"update_type": string/null, [0]
"file_type": string/null, [1]
"checksum_or_value_different": bool/null,
"size_different": bool/null,
"modification_time_different": bool/null,
"permissions_different": bool/null,
"owner_different": bool/null,
"group_different": bool/null,
"acl_different": bool/null,
"extended_attribute_different": bool/null,
"epoch": integer, [2]
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
}
[0] 'file sent', 'file received', 'local change or creation',
'hard link', 'not updated', 'message'
[1] 'file', 'directory', 'symlink', 'device', 'special file'
[2] naive timestamp if time and date fields exist and can be converted.
Examples:
$ rsync -i -a source/ dest | jc --rsync-s
{"type":"file","filename":"./","metadata":".d..t......","update_...}
...
$ cat rsync_backup.log | jc --rsync-s
{"type":"file","filename":"./","date":"2022/01/28","time":"03:53...}
...
<a id="jc.parsers.rsync_s.parse"></a>
### parse
```python
@add_jc_meta
def parse(data: Iterable[str],
raw: bool = False,
quiet: bool = False,
ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple]
```
Main text parsing generator function. Returns an iterator object.
Parameters:
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
Yields:
Dictionary. Raw or processed structured data.
Returns:
Iterator object (generator)
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.sfdisk"></a>
# jc.parsers.sfdisk
jc - JSON CLI output utility `sfdisk` command output parser
jc - JSON Convert `sfdisk` command output parser
Supports the following `sfdisk` options:
- `-l`
@@ -22,6 +24,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('sfdisk', sfdisk_command_output)
or
import jc.parsers.sfdisk
result = jc.parsers.sfdisk.parse(sfdisk_command_output)
@@ -53,7 +60,7 @@ Schema:
"boot": boolean,
"start": integer,
"end": integer,
"size": string, # Note: will be integer when using deprecated -d sfdisk option
"size": string, # [0]
"cyls": integer,
"mib": integer,
"blocks": integer,
@@ -66,6 +73,8 @@ Schema:
}
]
[0] will be integer when using deprecated -d sfdisk option
Examples:
# sfdisk -l | jc --sfdisk -p
@@ -75,7 +84,7 @@ Examples:
"cylinders": 2610,
"heads": 255,
"sectors_per_track": 63,
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0",
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, ...",
"partitions": [
{
"device": "/dev/sda1",
@@ -140,7 +149,7 @@ Examples:
"cylinders": "2610",
"heads": "255",
"sectors_per_track": "63",
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0",
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, co...",
"partitions": [
{
"device": "/dev/sda1",
@@ -198,16 +207,12 @@ Examples:
}
]
<a id="jc.parsers.sfdisk.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -215,14 +220,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.shadow"></a>
# jc.parsers.shadow
jc - JSON CLI output utility `/etc/shadow` file parser
jc - JSON Convert `/etc/shadow` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('shadow', shadow_file_output)
or
import jc.parsers.shadow
result = jc.parsers.shadow.parse(shadow_file_output)
@@ -99,16 +106,12 @@ Examples:
...
]
<a id="jc.parsers.shadow.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -116,14 +119,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,12 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ss"></a>
# jc.parsers.ss
jc - JSON CLI output utility `ss` command output parser
Extended information options like -e and -p are not supported and may cause parsing irregularities.
jc - JSON Convert `ss` command output parser
Extended information options like -e and -p are not supported and may cause
parsing irregularities.
Usage (cli):
@@ -15,12 +18,18 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ss', ss_command_output)
or
import jc.parsers.ss
result = jc.parsers.ss.parse(ss_command_output)
Schema:
Information from https://www.cyberciti.biz/files/ss.html used to define field names
Information from https://www.cyberciti.biz/files/ss.html used to define
field names
[
{
@@ -276,16 +285,12 @@ Examples:
}
]
<a id="jc.parsers.ss.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -293,14 +298,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,15 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.stat"></a>
# jc.parsers.stat
jc - JSON CLI output utility `stat` command output parser
The `xxx_epoch` calculated timestamp fields are naive (i.e. based on the local time of the system the parser is run on)
jc - JSON Convert `stat` command output parser
The `xxx_epoch_utc` calculated timestamp fields are timezone-aware and are only available if the timezone field is UTC.
The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the
local time of the system the parser is run on)
The `xxx_epoch_utc` calculated timestamp fields are timezone-aware and are
only available if the timezone field is UTC.
Usage (cli):
@@ -17,6 +21,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('stat', stat_command_output)
or
import jc.parsers.stat
result = jc.parsers.stat.parse(stat_command_output)
@@ -166,16 +175,12 @@ Examples:
...
]
<a id="jc.parsers.stat.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -183,14 +188,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,13 +1,17 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.stat_s"></a>
# jc.parsers.stat_s
jc - JSON CLI output utility `stat` command output streaming parser
# jc.parsers.stat\_s
jc - JSON Convert `stat` command output streaming parser
> This streaming parser outputs JSON Lines
The `xxx_epoch` calculated timestamp fields are naive (i.e. based on the local time of the system the parser is run on).
The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the
local time of the system the parser is run on).
The `xxx_epoch_utc` calculated timestamp fields are timezone-aware and are only available if the timezone field is UTC.
The `xxx_epoch_utc` calculated timestamp fields are timezone-aware and are
only available if the timezone field is UTC.
Usage (cli):
@@ -15,8 +19,17 @@ Usage (cli):
Usage (module):
import jc
# result is an iterable object (generator)
result = jc.parse('stat_s', stat_command_output.splitlines())
for item in result:
# do something
or
import jc.parsers.stat_s
result = jc.parsers.stat_s.parse(stat_command_output.splitlines()) # result is an iterable object
# result is an iterable object (generator)
result = jc.parsers.stat_s.parse(stat_command_output.splitlines())
for item in result:
# do something
@@ -54,9 +67,12 @@ Schema:
"rdev": integer,
"block_size": integer,
"unix_flags": string,
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # true if successfully parsed, false if error
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
@@ -65,29 +81,28 @@ Schema:
Examples:
$ stat | jc --stat-s
{"file":"(stdin)","unix_device":1027739696,"inode":1155,"flags":"crw--w----","links":1,"user":"kbrazil","group":"tty","rdev":268435456,"size":0,"access_time":"Jan 4 15:27:44 2022","modify_time":"Jan 4 15:27:44 2022","change_time":"Jan 4 15:27:44 2022","birth_time":"Dec 31 16:00:00 1969","block_size":131072,"blocks":0,"unix_flags":"0","access_time_epoch":1641338864,"access_time_epoch_utc":null,"modify_time_epoch":1641338864,"modify_time_epoch_utc":null,"change_time_epoch":1641338864,"change_time_epoch_utc":null,"birth_time_epoch":null,"birth_time_epoch_utc":null}
{"file":"(stdin)","unix_device":1027739696,"inode":1155,"flags":"cr...}
$ stat | jc --stat-s -r
{"file":"(stdin)","unix_device":"1027739696","inode":"1155","flags":"crw--w----","links":"1","user":"kbrazil","group":"tty","rdev":"268435456","size":"0","access_time":"Jan 4 15:28:08 2022","modify_time":"Jan 4 15:28:08 2022","change_time":"Jan 4 15:28:08 2022","birth_time":"Dec 31 16:00:00 1969","block_size":"131072","blocks":"0","unix_flags":"0"}
{"file":"(stdin)","unix_device":"1027739696","inode":"1155","flag...}
<a id="jc.parsers.stat_s.parse"></a>
### parse
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
## parse
```python
parse(data, raw=False, quiet=False, ignore_exceptions=False)
@add_jc_meta
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
```
Main text parsing generator function. Returns an iterator object.
Parameters:
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
raw: (boolean) output preprocessed JSON if True
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
@@ -97,9 +112,9 @@ Yields:
Returns:
Iterator object
Iterator object (generator)
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 0.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,14 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.sysctl"></a>
# jc.parsers.sysctl
jc - JSON CLI output utility `sysctl -a` command output parser
Note: Since `sysctl` output is not easily parsable only a very simple key/value object will be output. An attempt is made to convert obvious integers and floats. If no conversion is desired, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
jc - JSON Convert `sysctl -a` command output parser
Note: Since `sysctl` output is not easily parsable only a very simple
key/value object will be output. An attempt is made to convert obvious
integers and floats. If no conversion is desired, use the `-r`
command-line argument or the `raw=True` argument in `parse()`.
Usage (cli):
@@ -15,13 +20,18 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('sysctl', sysctl_command_output)
or
import jc.parsers.sysctl
result = jc.parsers.sysctl.parse(sysctl_command_output)
Schema:
{
"key1": string/integer/float, # best guess based on value
"key1": string/integer/float, # best guess based on value
"key2": string/integer/float,
"key3": string/integer/float
}
@@ -52,16 +62,12 @@ Examples:
...
}
<a id="jc.parsers.sysctl.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -69,14 +75,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.systemctl"></a>
# jc.parsers.systemctl
jc - JSON CLI output utility `systemctl` command output parser
jc - JSON Convert `systemctl` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('systemctl', systemctl_command_output)
or
import jc.parsers.systemctl
result = jc.parsers.systemctl.parse(systemctl_command_output)
@@ -37,14 +44,14 @@ Examples:
"load": "loaded",
"active": "active",
"sub": "waiting",
"description": "Arbitrary Executable File Formats File System Automount Point"
"description": "Arbitrary Executable File Formats File System ..."
},
{
"unit": "dev-block-8:2.device",
"load": "loaded",
"active": "active",
"sub": "plugged",
"description": "LVM PV 3klkIj-w1qk-DkJi-0XBJ-y3o7-i2Ac-vHqWBM on /dev/sda2 2"
"description": "LVM PV 3klkIj-w1qk-DkJi-0XBJ-y3o7-i2Ac-vHqWBM o..."
},
{
"unit": "dev-cdrom.device",
@@ -56,16 +63,12 @@ Examples:
...
]
<a id="jc.parsers.systemctl.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -73,14 +76,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.systemctl_lj"></a>
# jc.parsers.systemctl_lj
jc - JSON CLI output utility `systemctl list-jobs` command output parser
# jc.parsers.systemctl\_lj
jc - JSON Convert `systemctl list-jobs` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('systemctl_lj', systemctl_lj_command_output)
or
import jc.parsers.systemctl_lj
result = jc.parsers.systemctl_lj.parse(systemctl_lj_command_output)
@@ -73,16 +80,12 @@ Examples:
}
]
<a id="jc.parsers.systemctl_lj.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -90,14 +93,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,10 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.systemctl_ls"></a>
# jc.parsers.systemctl_ls
jc - JSON CLI output utility `systemctl list-sockets` command output parser
# jc.parsers.systemctl\_ls
jc - JSON Convert `systemctl list-sockets` command output
parser
Usage (cli):
@@ -13,6 +16,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('systemctl_ls', systemctl_ls_command_output)
or
import jc.parsers.systemctl_ls
result = jc.parsers.systemctl_ls.parse(systemctl_ls_command_output)
@@ -48,16 +56,12 @@ Examples:
...
]
<a id="jc.parsers.systemctl_ls.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -65,14 +69,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,10 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.systemctl_luf"></a>
# jc.parsers.systemctl_luf
jc - JSON CLI output utility `systemctl list-unit-files` command output parser
# jc.parsers.systemctl\_luf
jc - JSON Convert `systemctl list-unit-files` command output
parser
Usage (cli):
@@ -13,6 +16,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('systemctl_luf', systemctl_luf_command_output)
or
import jc.parsers.systemctl_luf
result = jc.parsers.systemctl_luf.parse(systemctl_luf_command_output)
@@ -44,16 +52,12 @@ Examples:
...
]
<a id="jc.parsers.systemctl_luf.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -61,14 +65,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,13 +1,19 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.systeminfo"></a>
# jc.parsers.systeminfo
jc - JSON CLI output utility `systeminfo` command output parser
jc - JSON Convert `systeminfo` command output parser
Blank or missing elements are set to `null`.
The `original_install_date_epoch` and `system_boot_time_epoch` calculated timestamp fields are naive (i.e. based on the local time of the system the parser is run on)
The `original_install_date_epoch` and `system_boot_time_epoch` calculated
timestamp fields are naive. (i.e. based on the local time of the system the
parser is run on)
The `original_install_date_epoch_utc` and `system_boot_time_epoch_utc` calculated timestamp fields are timezone-aware and are only available if the timezone field is UTC.
The `original_install_date_epoch_utc` and `system_boot_time_epoch_utc`
calculated timestamp fields are timezone-aware and are only available if
the timezone field is UTC.
Usage (cli):
@@ -15,6 +21,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('systeminfo', systeminfo_command_output)
or
import jc.parsers.systeminfo
result = jc.parsers.systeminfo.parse(systeminfo_command_output)
@@ -31,11 +42,11 @@ Schema:
"registered_organization": string,
"product_id": string,
"original_install_date": string,
"original_install_date_epoch": integer, # naive timestamp
"original_install_date_epoch_utc": integer, # timezone-aware timestamp
"original_install_date_epoch": integer, # [0]
"original_install_date_epoch_utc": integer, # [1]
"system_boot_time": string,
"system_boot_time_epoch": integer, # naive timestamp
"system_boot_time_epoch_utc": integer, # timezone-aware timestamp
"system_boot_time_epoch": integer, # [0]
"system_boot_time_epoch_utc": integer, # [1]
"system_manufacturer": string,
"system_model": string,
"system_type": string,
@@ -80,6 +91,9 @@ Schema:
}
}
[0] naive timestamp
[1] timezone-aware timestamp
Examples:
$ systeminfo | jc --systeminfo -p
@@ -102,9 +116,9 @@ Examples:
"Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz"
],
"bios_version": "Dell Inc. 1.16.2, 4/21/2020",
"windows_directory": "C:\WINDOWS",
"system_directory": "C:\WINDOWS\system32",
"boot_device": "\Device\HarddiskVolume2",
"windows_directory": "C:\\WINDOWS",
"system_directory": "C:\\WINDOWS\\system32",
"boot_device": "\\Device\\HarddiskVolume2",
"system_locale": "en-us;English (United States)",
"input_locale": "en-us;English (United States)",
"time_zone": "(UTC+00:00) UTC",
@@ -113,9 +127,9 @@ Examples:
"virtual_memory_max_size_mb": 37367,
"virtual_memory_available_mb": 22266,
"virtual_memory_in_use_mb": 15101,
"page_file_locations": "C:\pagefile.sys",
"page_file_locations": "C:\\pagefile.sys",
"domain": "test.com",
"logon_server": "\\TESTDC01",
"logon_server": "\\\\TESTDC01",
"hotfixs": [
"KB2693643",
"KB4601054"
@@ -164,9 +178,9 @@ Examples:
"Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz"
],
"bios_version": "Dell Inc. 1.16.2, 4/21/2020",
"windows_directory": "C:\WINDOWS",
"system_directory": "C:\WINDOWS\system32",
"boot_device": "\Device\HarddiskVolume2",
"windows_directory": "C:\\WINDOWS",
"system_directory": "C:\\WINDOWS\\system32",
"boot_device": "\\Device\\HarddiskVolume2",
"system_locale": "en-us;English (United States)",
"input_locale": "en-us;English (United States)",
"time_zone": "(UTC+00:00) UTC",
@@ -175,9 +189,9 @@ Examples:
"virtual_memory_max_size_mb": "37,367 MB",
"virtual_memory_available_mb": "22,266 MB",
"virtual_memory_in_use_mb": "15,101 MB",
"page_file_locations": "C:\pagefile.sys",
"page_file_locations": "C:\\pagefile.sys",
"domain": "test.com",
"logon_server": "\\TESTDC01",
"logon_server": "\\\\TESTDC01",
"hotfixs": [
"KB2693643",
"KB4601054"
@@ -202,16 +216,12 @@ Examples:
}
}
<a id="jc.parsers.systeminfo.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -219,14 +229,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: win32
Version 1.1 by Jon Smith (jon@rebelliondefense.com)
Version 1.2 by Jon Smith (jon@rebelliondefense.com)

View File

@@ -1,20 +1,31 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.time"></a>
# jc.parsers.time
jc - JSON CLI output utility `/usr/bin/time` command output parser
Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be used to redirect the output to a file that can be read by `jc`.
jc - JSON Convert `/usr/bin/time` command output parser
Alternatively, the output from `/usr/bin/time` can be redirected to `STDOUT` so `jc` can receive it.
Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be
used to redirect the output to a file that can be read by `jc`.
Note: `/usr/bin/time` is similar but different from the Bash builtin `time` command.
Alternatively, the output from `/usr/bin/time` can be redirected to `STDOUT`
so `jc` can receive it.
Note: `/usr/bin/time` is similar but different from the Bash builtin
`time` command.
Usage (cli):
$ /usr/bin/time -o timefile.out sleep 2.5; cat timefile.out | jc --time -p
$ /usr/bin/time -o timefile.out sleep 2; cat timefile.out | \\
jc --time -p
Usage (module):
import jc
result = jc.parse('time', time_command_output)
or
import jc.parsers.time
result = jc.parsers.time.parse(time_command_output)
@@ -39,8 +50,8 @@ Schema:
"average_unshared_stack_size": integer,
"average_shared_memory_size": integer,
"maximum_resident_set_size": integer,
"block_input_operations": integer, # aka File system inputs
"block_output_operations": integer, # aka File system outputs
"block_input_operations": integer, # [0]
"block_output_operations": integer, # [1]
"major_pagefaults": integer,
"minor_pagefaults": integer,
"swaps": integer,
@@ -60,15 +71,19 @@ Schema:
"exit_status": integer
}
[0] aka File system inputs
[1] aka File system outputs
Examples:
$ /usr/bin/time --verbose -o timefile.out sleep 2.5; cat timefile.out | jc --time -p
$ /usr/bin/time --verbose -o timefile.out sleep 2; cat timefile.out | \\
jc --time -p
{
"command_being_timed": "sleep 2.5",
"command_being_timed": "sleep 2",
"user_time": 0.0,
"system_time": 0.0,
"cpu_percent": 0,
"elapsed_time": "0:02.50",
"elapsed_time": "0:02.00",
"average_shared_text_size": 0,
"average_unshared_data_size": 0,
"average_stack_size": 0,
@@ -94,13 +109,14 @@ Examples:
"elapsed_time_total_seconds": 2.5
}
$ /usr/bin/time --verbose -o timefile.out sleep 2.5; cat timefile.out | jc --time -p -r
$ /usr/bin/time --verbose -o timefile.out sleep 2; cat timefile.out | \\
jc --time -p -r
{
"command_being_timed": ""sleep 2.5"",
"command_being_timed": "\"sleep 2\"",
"user_time": "0.00",
"system_time": "0.00",
"cpu_percent": "0",
"elapsed_time": "0:02.50",
"elapsed_time": "0:02.00",
"average_shared_text_size": "0",
"average_unshared_data_size": "0",
"average_stack_size": "0",
@@ -121,16 +137,12 @@ Examples:
"exit_status": "0"
}
<a id="jc.parsers.time.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -138,14 +150,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,9 +1,12 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.timedatectl"></a>
# jc.parsers.timedatectl
jc - JSON CLI output utility `timedatectl` command output parser
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the `universal_time` field is available.
jc - JSON Convert `timedatectl` command output parser
The `epoch_utc` calculated timestamp field is timezone-aware and is only
available if the `universal_time` field is available.
Usage (cli):
@@ -15,6 +18,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('timedatectl', timedatectl_command_output)
or
import jc.parsers.timedatectl
result = jc.parsers.timedatectl.parse(timedatectl_command_output)
@@ -23,7 +31,7 @@ Schema:
{
"local_time": string,
"universal_time": string,
"epoch_utc": integer, # timezone-aware timestamp
"epoch_utc": integer, # timezone-aware
"rtc_time": string,
"time_zone": string,
"ntp_enabled": boolean,
@@ -61,16 +69,12 @@ Examples:
"dst_active": "yes"
}
<a id="jc.parsers.timedatectl.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -78,14 +82,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.tracepath"></a>
# jc.parsers.tracepath
jc - JSON CLI output utility `tracepath` command output parser
jc - JSON Convert `tracepath` command output parser
Supports `tracepath` and `tracepath6` output.
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('tracepath', tracepath_command_output)
or
import jc.parsers.tracepath
result = jc.parsers.tracepath.parse(tracepath_command_output)
@@ -129,16 +136,12 @@ Examples:
]
}
<a id="jc.parsers.tracepath.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -146,14 +149,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,13 +1,18 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.traceroute"></a>
# jc.parsers.traceroute
jc - JSON CLI output utility `traceroute` command output parser
jc - JSON Convert `traceroute` command output parser
Supports `traceroute` and `traceroute6` output.
Note: On some operating systems you will need to redirect `STDERR` to `STDOUT` for destination info since the header line is sent to `STDERR`. A warning message will be printed to `STDERR` if the header row is not found.
Note: On some operating systems you will need to redirect `STDERR` to
`STDOUT` for destination info since the header line is sent to
`STDERR`. A warning message will be printed to `STDERR` if the
header row is not found.
e.g. `$ traceroute 8.8.8.8 2>&1 | jc --traceroute`
e.g. `$ traceroute 8.8.8.8 2>&1 | jc --traceroute`
Usage (cli):
@@ -19,6 +24,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('traceroute', traceroute_command_output)
or
import jc.parsers.traceroute
result = jc.parsers.traceroute.parse(traceroute_command_output)
@@ -115,16 +125,12 @@ Examples:
]
}
<a id="jc.parsers.traceroute.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -132,14 +138,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ufw"></a>
# jc.parsers.ufw
jc - JSON CLI output utility `ufw status` command output parser
jc - JSON Convert `ufw status` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ufw', ufw_command_output)
or
import jc.parsers.ufw
result = jc.parsers.ufw.parse(ufw_command_output)
@@ -43,7 +50,7 @@ Schema:
"end": integer
}
],
"to_service": string, # null if any to ports or port_ranges are set
"to_service": string, # [0]
"from_ip": string,
"from_ip_prefix": integer,
"from_interface": string,
@@ -57,12 +64,15 @@ Schema:
"end": integer
}
],
"from_service": string, # null if any from ports or port_ranges are set
"from_service": string, # [1]
"comment": string # null if no comment
}
]
}
[0] null if any 'to' ports or port_ranges are set
[1] null if any 'from' ports or port_ranges are set
Examples:
$ ufw status verbose | jc --ufw -p
@@ -195,16 +205,12 @@ Examples:
]
}
<a id="jc.parsers.ufw.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -212,14 +218,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,17 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ufw_appinfo"></a>
# jc.parsers.ufw_appinfo
jc - JSON CLI output utility `ufw app info [application]` command output parser
# jc.parsers.ufw\_appinfo
Supports individual apps via `ufw app info [application]` and all apps list via `ufw app info all`.
jc - JSON Convert `ufw app info [application]` command
output parser
Because `ufw` application definitions allow overlapping ports and port ranges, this parser preserves that behavior, but also provides `normalized` lists and ranges that remove duplicate ports and merge overlapping ranges.
Supports individual apps via `ufw app info [application]` and all apps list
via `ufw app info all`.
Because `ufw` application definitions allow overlapping ports and port
ranges, this parser preserves that behavior, but also provides `normalized`
lists and ranges that remove duplicate ports and merge overlapping ranges.
Usage (cli):
@@ -17,6 +23,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('ufw_appinfo', ufw_appinfo_command_output)
or
import jc.parsers.ufw_appinfo
result = jc.parsers.ufw_appinfo.parse(ufw_appinfo_command_output)
@@ -32,7 +43,7 @@ Schema:
],
"tcp_ranges": [
{
"start": integer, # 'any' is converted to start/end: 0/65535
"start": integer, # [0]
"end": integer
}
],
@@ -41,31 +52,35 @@ Schema:
],
"udp_ranges": [
{
"start": integer, # 'any' is converted to start/end: 0/65535
"start": integer, # [0]
"end": integer
}
],
"normalized_tcp_list": [
integers # duplicates and overlapping are removed
integers # [1]
],
"normalized_tcp_ranges": [
{
"start": integer, # 'any' is converted to start/end: 0/65535
"end": integers # overlapping are merged
"start": integer, # [0]
"end": integers # [2]
}
],
"normalized_udp_list": [
integers # duplicates and overlapping are removed
integers # [1]
],
"normalized_udp_ranges": [
{
"start": integer, # 'any' is converted to start/end: 0/65535
"end": integers # overlapping are merged
"start": integer, # [0]
"end": integers # [2]
}
]
}
]
[0] 'any' is converted to start/end: 0/65535
[1] duplicates and overlapping are removed
[2] overlapping are merged
Examples:
$ ufw app info MSN | jc --ufw-appinfo -p
@@ -128,16 +143,12 @@ Examples:
}
]
<a id="jc.parsers.ufw_appinfo.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -145,14 +156,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.uname"></a>
# jc.parsers.uname
jc - JSON CLI output utility `uname -a` command output parser
jc - JSON Convert `uname -a` command output parser
Note: Must use `uname -a`
@@ -15,6 +17,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('uname', uname_command_output)
or
import jc.parsers.uname
result = jc.parsers.uname.parse(uname_command_output)
@@ -45,16 +52,12 @@ Example:
"kernel_version": "#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019"
}
<a id="jc.parsers.uname.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -62,14 +65,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

70
docs/parsers/universal.md Normal file
View File

@@ -0,0 +1,70 @@
# Table of Contents
* [jc.parsers.universal](#jc.parsers.universal)
* [simple\_table\_parse](#jc.parsers.universal.simple_table_parse)
* [sparse\_table\_parse](#jc.parsers.universal.sparse_table_parse)
<a id="jc.parsers.universal"></a>
# jc.parsers.universal
jc - JSON Convert universal parsers
<a id="jc.parsers.universal.simple_table_parse"></a>
### simple\_table\_parse
```python
def simple_table_parse(data: List[str]) -> List[Dict]
```
Parse simple tables. The last column may contain data with spaces.
Parameters:
data: (list) Text data to parse that has been split into lines
via .splitlines(). Item 0 must be the header row.
Any spaces in header names should be changed to
underscore '_'. You should also ensure headers are
lowercase by using .lower().
Also, ensure there are no blank lines (list items)
in the data.
Returns:
List of Dictionaries
<a id="jc.parsers.universal.sparse_table_parse"></a>
### sparse\_table\_parse
```python
def sparse_table_parse(data: List[str], delim: str = '\u2063') -> List[Dict]
```
Parse tables with missing column data or with spaces in column data.
Parameters:
data: (list) Text data to parse that has been split into lines
via .splitlines(). Item 0 must be the header row.
Any spaces in header names should be changed to
underscore '_'. You should also ensure headers are
lowercase by using .lower(). Do not change the
position of header names as the positions are used
to find the data.
Also, ensure there are no blank lines (list items)
in the data.
delim: (string) Delimiter to use. By default `u\\2063`
(invisible separator) is used since it is unlikely
to ever be seen in terminal output. You can change
this for troubleshooting purposes or if there is a
delimiter conflict with your data.
Returns:
List of Dictionaries

View File

@@ -1,11 +1,15 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.upower"></a>
# jc.parsers.upower
jc - JSON CLI output utility `upower` command output parser
The `updated_epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
jc - JSON Convert `upower` command output parser
The `updated_epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
The `updated_epoch` calculated timestamp field is naive. (i.e. based on the
local time of the system the parser is run on)
The `updated_epoch_utc` calculated timestamp field is timezone-aware and is
only available if the timezone field is UTC.
Usage (cli):
@@ -17,6 +21,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('upower', upower_command_output)
or
import jc.parsers.upower
result = jc.parsers.upower.parse(upower_command_output)
@@ -29,8 +38,8 @@ Schema:
"native_path": string,
"power_supply": boolean,
"updated": string,
"updated_epoch": integer, # null if date-time conversion fails
"updated_epoch_utc": integer, # null if date-time conversion fails
"updated_epoch": integer, # [0]
"updated_epoch_utc": integer, # [0]
"updated_seconds_ago": integer,
"has_history": boolean,
"has_statistics": boolean,
@@ -82,12 +91,14 @@ Schema:
}
]
[0] null if date-time conversion fails
Examples:
$ upower -i /org/freedesktop/UPower/devices/battery | jc --upower -p
[
{
"native_path": "/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0",
"native_path": "/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/p...",
"vendor": "NOTEBOOK",
"model": "BAT",
"serial": "0001",
@@ -146,7 +157,7 @@ Examples:
$ upower -i /org/freedesktop/UPower/devices/battery | jc --upower -p -r
[
{
"native_path": "/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0",
"native_path": "/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/p...",
"vendor": "NOTEBOOK",
"model": "BAT",
"serial": "0001",
@@ -192,16 +203,12 @@ Examples:
}
]
<a id="jc.parsers.upower.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -209,14 +216,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.uptime"></a>
# jc.parsers.uptime
jc - JSON CLI output utility `uptime` command output parser
jc - JSON Convert `uptime` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('uptime', uptime_command_output)
or
import jc.parsers.uptime
result = jc.parsers.uptime.parse(uptime_command_output)
@@ -63,16 +70,12 @@ Example:
"load_15m": "1.94"
}
<a id="jc.parsers.uptime.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -80,14 +83,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,13 +1,17 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.vmstat"></a>
# jc.parsers.vmstat
jc - JSON CLI output utility `vmstat` command output parser
jc - JSON Convert `vmstat` command output parser
Options supported: `-a`, `-w`, `-d`, `-t`
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
The `epoch` calculated timestamp field is naive. (i.e. based on the local
time of the system the parser is run on)
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
The `epoch_utc` calculated timestamp field is timezone-aware and is only
available if the timezone field is UTC.
Usage (cli):
@@ -19,6 +23,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('vmstat', vmstat_command_output)
or
import jc.parsers.vmstat
result = jc.parsers.vmstat.parse(vmstat_command_output)
@@ -58,11 +67,14 @@ Schema:
"io_seconds": integer,
"timestamp": string,
"timezone": string,
"epoch": integer, # naive timestamp if -t flag is used
"epoch_utc": integer # aware timestamp if -t flag is used and UTC TZ
"epoch": integer, # [0]
"epoch_utc": integer # [1]
}
]
[0] naive timestamp if -t flag is used
[1] aware timestamp if -t flag is used and UTC TZ
Examples:
$ vmstat | jc --vmstat -p
@@ -119,16 +131,12 @@ Examples:
}
]
<a id="jc.parsers.vmstat.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -136,14 +144,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,102 +1,127 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.vmstat_s"></a>
# jc.parsers.vmstat_s
jc - JSON CLI output utility `vmstat` command output streaming parser
# jc.parsers.vmstat\_s
jc - JSON Convert `vmstat` command output streaming parser
> This streaming parser outputs JSON Lines
Options supported: `-a`, `-w`, `-d`, `-t`
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
The `epoch` calculated timestamp field is naive. (i.e. based on the local
time of the system the parser is run on)
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
The `epoch_utc` calculated timestamp field is timezone-aware and is only
available if the timezone field is UTC.
Usage (cli):
$ vmstat | jc --vmstat-s
> Note: When piping `jc` converted `vmstat` output to other processes it may appear the output is hanging due to the OS pipe buffers. This is because `vmstat` output is too small to quickly fill up the buffer. Use the `-u` option to unbuffer the `jc` output if you would like immediate output. See the [readme](https://github.com/kellyjonbrazil/jc/tree/master#unbuffering-output) for more information.
> Note: When piping `jc` converted `vmstat` output to other processes it may
appear the output is hanging due to the OS pipe buffers. This is because
`vmstat` output is too small to quickly fill up the buffer. Use the `-u`
option to unbuffer the `jc` output if you would like immediate output. See
the [readme](https://github.com/kellyjonbrazil/jc/tree/master#unbuffering-output)
for more information.
Usage (module):
import jc
# result is an iterable object (generator)
result = jc.parse('vmstat_s', vmstat_command_output.splitlines())
for item in result:
# do something
or
import jc.parsers.vmstat_s
result = jc.parsers.vmstat_s.parse(vmstat_command_output.splitlines()) # result is an iterable object
# result is an iterable object (generator)
result = jc.parsers.vmstat_s.parse(vmstat_command_output.splitlines())
for item in result:
# do something
Schema:
{
"runnable_procs": integer,
"uninterruptible_sleeping_procs": integer,
"virtual_mem_used": integer,
"free_mem": integer,
"buffer_mem": integer,
"cache_mem": integer,
"inactive_mem": integer,
"active_mem": integer,
"swap_in": integer,
"swap_out": integer,
"blocks_in": integer,
"blocks_out": integer,
"interrupts": integer,
"context_switches": integer,
"user_time": integer,
"system_time": integer,
"idle_time": integer,
"io_wait_time": integer,
"stolen_time": integer,
"disk": string,
"total_reads": integer,
"merged_reads": integer,
"sectors_read": integer,
"reading_ms": integer,
"total_writes": integer,
"merged_writes": integer,
"sectors_written": integer,
"writing_ms": integer,
"current_io": integer,
"io_seconds": integer,
"timestamp": string,
"timezone": string,
"epoch": integer, # naive timestamp if -t flag is used
"epoch_utc": integer # aware timestamp if -t flag is used and UTC TZ
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
"runnable_procs": integer,
"uninterruptible_sleeping_procs": integer,
"virtual_mem_used": integer,
"free_mem": integer,
"buffer_mem": integer,
"cache_mem": integer,
"inactive_mem": integer,
"active_mem": integer,
"swap_in": integer,
"swap_out": integer,
"blocks_in": integer,
"blocks_out": integer,
"interrupts": integer,
"context_switches": integer,
"user_time": integer,
"system_time": integer,
"idle_time": integer,
"io_wait_time": integer,
"stolen_time": integer,
"disk": string,
"total_reads": integer,
"merged_reads": integer,
"sectors_read": integer,
"reading_ms": integer,
"total_writes": integer,
"merged_writes": integer,
"sectors_written": integer,
"writing_ms": integer,
"current_io": integer,
"io_seconds": integer,
"timestamp": string,
"timezone": string,
"epoch": integer, # [0]
"epoch_utc": integer # [1]
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # true if successfully parsed, false if error
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
"success": boolean, # [2]
"error": string, # [3]
"line": string # [3]
}
}
[0] naive timestamp if -t flag is used
[1] aware timestamp if -t flag is used and UTC TZ
[2] false if error parsing
[3] exists if "success" is false
Examples:
$ vmstat | jc --vmstat-s
{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794468,"buffer_mem":2108,"cache_mem":741208,"inactive_mem":null,"active_mem":null,"swap_in":0,"swap_out":0,"blocks_in":1,"blocks_out":3,"interrupts":29,"context_switches":57,"user_time":0,"system_time":0,"idle_time":99,"io_wait_time":0,"stolen_time":0,"timestamp":null,"timezone":null}
{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem...}
...
$ vmstat | jc --vmstat-s -r
{"runnable_procs":"2","uninterruptible_sleeping_procs":"0","virtual_mem_used":"0","free_mem":"2794468","buffer_mem":"2108","cache_mem":"741208","inactive_mem":null,"active_mem":null,"swap_in":"0","swap_out":"0","blocks_in":"1","blocks_out":"3","interrupts":"29","context_switches":"57","user_time":"0","system_time":"0","idle_time":"99","io_wait_time":"0","stolen_time":"0","timestamp":null,"timezone":null}
{"runnable_procs":"2","uninterruptible_sleeping_procs":"0","virtua...}
...
<a id="jc.parsers.vmstat_s.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False, ignore_exceptions=False)
@add_jc_meta
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
```
Main text parsing generator function. Returns an iterator object.
Parameters:
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
raw: (boolean) output preprocessed JSON if True
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
@@ -106,9 +131,9 @@ Yields:
Returns:
Iterator object
Iterator object (generator)
## Parser Information
### Parser Information
Compatibility: linux
Version 0.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.w"></a>
# jc.parsers.w
jc - JSON CLI output utility `w` command output parser
jc - JSON Convert `w` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('w', w_command_output)
or
import jc.parsers.w
result = jc.parsers.w.parse(w_command_output)
@@ -101,16 +108,12 @@ Examples:
}
]
<a id="jc.parsers.w.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -118,14 +121,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.wc"></a>
# jc.parsers.wc
jc - JSON CLI output utility `wc` command output parser
jc - JSON Convert `wc` command output parser
Usage (cli):
@@ -13,6 +15,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('wc', wc_command_output)
or
import jc.parsers.wc
result = jc.parsers.wc.parse(wc_command_output)
@@ -52,16 +59,12 @@ Examples:
...
]
<a id="jc.parsers.wc.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -69,14 +72,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,11 +1,14 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.who"></a>
# jc.parsers.who
jc - JSON CLI output utility `who` command output parser
jc - JSON Convert `who` command output parser
Accepts any of the following who options (or no options): `-aTH`
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
The `epoch` calculated timestamp field is naive. (i.e. based on the local
time of the system the parser is run on)
Usage (cli):
@@ -17,6 +20,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('who', who_command_output)
or
import jc.parsers.who
result = jc.parsers.who.parse(who_command_output)
@@ -29,7 +37,7 @@ Schema:
"writeable_tty": string,
"tty": string,
"time": string,
"epoch": integer, # naive timestamp. null if time cannot be converted
"epoch": integer, # [0]
"idle": string,
"pid": integer,
"from": string,
@@ -37,6 +45,8 @@ Schema:
}
]
[0] naive timestamp. null if time cannot be converted
Examples:
$ who -a | jc --who -p
@@ -130,16 +140,12 @@ Examples:
}
]
<a id="jc.parsers.who.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -147,14 +153,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.xml"></a>
# jc.parsers.xml
jc - JSON CLI output utility `XML` file parser
jc - JSON Convert `XML` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('xml', xml_file_output)
or
import jc.parsers.xml
result = jc.parsers.xml.parse(xml_file_output)
@@ -68,16 +75,12 @@ Examples:
...
}
<a id="jc.parsers.xml.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -85,14 +88,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

168
docs/parsers/xrandr.md Normal file
View File

@@ -0,0 +1,168 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.xrandr"></a>
# jc.parsers.xrandr
jc - JSON Convert `xrandr` command output parser
Usage (cli):
$ xrandr | jc --xrandr
or
$ jc xrandr
Usage (module):
import jc
result = jc.parse('xrandr', xrandr_command_output)
or
import jc.parsers.xrandr
result = jc.parsers.xrandr.parse(xrandr_command_output)
Schema:
{
"screens": [
{
"screen_number": integer,
"minimum_width": integer,
"minimum_height": integer,
"current_width": integer,
"current_height": integer,
"maximum_width": integer,
"maximum_height": integer,
"associated_device": {
"associated_modes": [
{
"resolution_width": integer,
"resolution_height": integer,
"is_high_resolution": boolean,
"frequencies": [
{
"frequency": float,
"is_current": boolean,
"is_preferred": boolean
}
]
}
]
},
"is_connected": boolean,
"is_primary": boolean,
"device_name": string,
"resolution_width": integer,
"resolution_height": integer,
"offset_width": integer,
"offset_height": integer,
"dimension_width": integer,
"dimension_height": integer
}
],
"unassociated_devices": [
{
"associated_modes": [
{
"resolution_width": integer,
"resolution_height": integer,
"is_high_resolution": boolean,
"frequencies": [
{
"frequency": float,
"is_current": boolean,
"is_preferred": boolean
}
]
}
]
}
]
}
Examples:
$ xrandr | jc --xrandr -p
{
"screens": [
{
"screen_number": 0,
"minimum_width": 8,
"minimum_height": 8,
"current_width": 1920,
"current_height": 1080,
"maximum_width": 32767,
"maximum_height": 32767,
"associated_device": {
"associated_modes": [
{
"resolution_width": 1920,
"resolution_height": 1080,
"is_high_resolution": false,
"frequencies": [
{
"frequency": 60.03,
"is_current": true,
"is_preferred": true
},
{
"frequency": 59.93,
"is_current": false,
"is_preferred": false
}
]
},
{
"resolution_width": 1680,
"resolution_height": 1050,
"is_high_resolution": false,
"frequencies": [
{
"frequency": 59.88,
"is_current": false,
"is_preferred": false
}
]
}
],
"is_connected": true,
"is_primary": true,
"device_name": "eDP1",
"resolution_width": 1920,
"resolution_height": 1080,
"offset_width": 0,
"offset_height": 0,
"dimension_width": 310,
"dimension_height": 170
}
}
],
"unassociated_devices": []
}
<a id="jc.parsers.xrandr.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.0 by Kevin Lyter (lyter_git at sent.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.yaml"></a>
# jc.parsers.yaml
jc - JSON CLI output utility `YAML` file parser
jc - JSON Convert `YAML` file parser
Usage (cli):
@@ -9,6 +11,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('yaml', yaml_file_output)
or
import jc.parsers.yaml
result = jc.parsers.yaml.parse(yaml_file_output)
@@ -82,16 +89,12 @@ Examples:
}
]
<a id="jc.parsers.yaml.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -99,14 +102,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries representing the YAML documents.
## Parser Information
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -1,7 +1,9 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.zipinfo"></a>
# jc.parsers.zipinfo
jc - JSON CLI output utility `zipinfo` command output parser
jc - JSON Convert `zipinfo` command output parser
Options supported:
- none
@@ -18,6 +20,11 @@ Usage (cli):
Usage (module):
import jc
result = jc.parse('zipinfo', zipinfo_command_output)
or
import jc.parsers.zipinfo
result = jc.parsers.zipinfo.parse(zipinfo_command_output)
@@ -37,7 +44,7 @@ Schema:
{
"flags": string,
"zipversion": string,
"zipunder": string
"zipunder": string,
"filesize": integer,
"type": string,
"method": string,
@@ -77,16 +84,12 @@ Examples:
},
...
<a id="jc.parsers.zipinfo.parse"></a>
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
### parse
## parse
```python
parse(data, raw=False, quiet=False)
def parse(data, raw=False, quiet=False)
```
Main text parsing function
@@ -94,14 +97,14 @@ Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
## Parser Information
### Parser Information
Compatibility: linux, darwin
Version 0.01 by Matt J (https://github.com/listuser)
Version 1.0 by Matt J (https://github.com/listuser)

View File

@@ -1,75 +1,121 @@
<a id="jc"></a>
# jc
JC - JSON CLI output utility
JC - JSON Convert
* kellyjonbrazil@gmail.com
This package serializes the output of many standard unix command line tools to JSON format.
This package converts the output of many standard unix command line tools
and file-types to dictionaries and lists of dictionaries.
For documentation on each parser, see the [documentation site](https://kellyjonbrazil.github.io/jc/).
## Interactive Documentation
CLI Example:
>>> help('jc')
>>> help('jc.lib')
>>> help('jc.utils')
>>> help('jc.streaming')
>>> help('jc.parsers.universal')
>>> jc.get_help('parser_module_name')
$ dig example.com | jc --dig -p
[
{
"id": 2951,
"opcode": "QUERY",
"status": "NOERROR",
"flags": [
"qr",
"rd",
"ra"
],
"query_num": 1,
"answer_num": 1,
"authority_num": 0,
"additional_num": 1,
"opt_pseudosection": {
"edns": {
"version": 0,
"flags": [],
"udp": 4096
}
},
"question": {
"name": "example.com.",
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "example.com.",
"class": "IN",
"type": "A",
"ttl": 39302,
"data": "93.184.216.34"
}
],
"query_time": 49,
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
"when": "Fri Apr 16 16:05:10 PDT 2021",
"rcvd": 56,
"when_epoch": 1618614310,
"when_epoch_utc": null
}
]
## Online Documentation
Module Example:
### Latest
>>> import jc.parsers.dig
https://github.com/kellyjonbrazil/jc/tree/master/docs
### Specific Version
Replace `<full_version_number>` - e.g. `1.17.7`:
`https://github.com/kellyjonbrazil/jc/tree/v<full_version_number>/docs`
Specific versions can also be selected by tag in the branch dropdown menu.
## Usage Example
>>> import subprocess
>>> import jc
>>>
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
text=True)
>>> data = jc.parse('dig', cmd_output)
>>> data
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
Alternatively, you can bypass the high-level API and call the parser
modules directly:
>>> import subprocess
>>> import jc.parsers.dig
>>>
>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
text=True)
>>> data = jc.parsers.dig.parse(cmd_output)
>>>
>>> data
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num':
1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp':
4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.',
'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': '93.184.216.34'}], 'query_time': 52, 'server':
'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': 'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56,
'when_epoch': 1618614780, 'when_epoch_utc': None}]
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
## Available Functions
Use `help(jc.lib)` for details.
### parse
parse(
parser_module_name: str,
data: str | Iterable
) -> dict | list[dict] | Iterable[dict]
High-level API to easily access the parser. This API will find both
built-in parsers and local plugin parsers.
### parser_info
parser_info(parser_module_name: str) -> dict
Get the metadata for a particular parser.
### all_parser_info
all_parser_info() -> list[dict]
Get the metadata for all parsers.
### get_help
get_help(parser_module_name: str) -> None
Convenience function to display the help screen for a parser using
its module name.
### parser_mod_list
parser_mod_list() -> list
Get a list of all available parser module names to be used in
`parse()`, `parser_info()`, and `get_help()`.
### plugin_parser_mod_list
plugin_parser_mod_list() -> list
Get a list of plugin parser module names to be used in
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
`parser_mod_list()`.
### standard_parser_mod_list
standard_parser_mod_list() -> list
Get a list of standard parser module names to be used in
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
`parser_mod_list()` and does not contain any streaming parsers.
### streaming_parser_mod_list
streaming_parser_mod_list() -> list
Get a list of streaming parser module names to be used in
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
`parser_mod_list()`.

115
docs/streaming.md Normal file
View File

@@ -0,0 +1,115 @@
# Table of Contents
* [jc.streaming](#jc.streaming)
* [streaming\_input\_type\_check](#jc.streaming.streaming_input_type_check)
* [streaming\_line\_input\_type\_check](#jc.streaming.streaming_line_input_type_check)
* [stream\_success](#jc.streaming.stream_success)
* [stream\_error](#jc.streaming.stream_error)
* [add\_jc\_meta](#jc.streaming.add_jc_meta)
* [raise\_or\_yield](#jc.streaming.raise_or_yield)
<a id="jc.streaming"></a>
# jc.streaming
jc - JSON Convert streaming utils
<a id="jc.streaming.streaming_input_type_check"></a>
### streaming\_input\_type\_check
```python
def streaming_input_type_check(data: Iterable) -> None
```
Ensure input data is an iterable, but not a string or bytes. Raises
`TypeError` if not.
<a id="jc.streaming.streaming_line_input_type_check"></a>
### streaming\_line\_input\_type\_check
```python
def streaming_line_input_type_check(line: str) -> None
```
Ensure each line is a string. Raises `TypeError` if not.
<a id="jc.streaming.stream_success"></a>
### stream\_success
```python
def stream_success(output_line: Dict, ignore_exceptions: bool) -> Dict
```
Add `_jc_meta` object to output line if `ignore_exceptions=True`
<a id="jc.streaming.stream_error"></a>
### stream\_error
```python
def stream_error(e: BaseException, line: str) -> Dict
```
Return an error `_jc_meta` field.
<a id="jc.streaming.add_jc_meta"></a>
### add\_jc\_meta
```python
def add_jc_meta(func)
```
Decorator for streaming parsers to add stream_success and stream_error
objects. This simplifies the yield lines in the streaming parsers.
With the decorator on parse():
# successfully parsed line:
yield output_line if raw else _process(output_line)
# unsuccessfully parsed line:
except Exception as e:
yield raise_or_yield(ignore_exceptions, e, line)
Without the decorator on parse():
# successfully parsed line:
if raw:
yield stream_success(output_line, ignore_exceptions)
else:
stream_success(_process(output_line), ignore_exceptions)
# unsuccessfully parsed line:
except Exception as e:
yield stream_error(raise_or_yield(ignore_exceptions, e, line))
In all cases above:
output_line: (Dict) successfully parsed line yielded as a dict
e: (BaseException) exception object as the first value
of the tuple if the line was not successfully parsed.
line: (str) string of the original line that did not
successfully parse.
ignore_exceptions: (bool) continue processing lines and ignore
exceptions if True.
<a id="jc.streaming.raise_or_yield"></a>
### raise\_or\_yield
```python
def raise_or_yield(ignore_exceptions: bool, e: BaseException,
line: str) -> tuple
```
Return the exception object and line string if ignore_exceptions is
True. Otherwise, re-raise the exception from the exception object with
an annotation.

View File

@@ -1,15 +1,34 @@
# Table of Contents
# utils
jc - JSON CLI output utility utils
* [jc.utils](#jc.utils)
* [warning\_message](#jc.utils.warning_message)
* [error\_message](#jc.utils.error_message)
* [compatibility](#jc.utils.compatibility)
* [has\_data](#jc.utils.has_data)
* [convert\_to\_int](#jc.utils.convert_to_int)
* [convert\_to\_float](#jc.utils.convert_to_float)
* [convert\_to\_bool](#jc.utils.convert_to_bool)
* [input\_type\_check](#jc.utils.input_type_check)
* [timestamp](#jc.utils.timestamp)
* [\_\_init\_\_](#jc.utils.timestamp.__init__)
<a id="jc.utils"></a>
# jc.utils
jc - JSON Convert utils
<a id="jc.utils.warning_message"></a>
### warning\_message
## warning_message
```python
warning_message(message_lines)
def warning_message(message_lines: List[str]) -> None
```
Prints warning message for non-fatal issues. The first line is prepended with
'jc: Warning - ' and subsequent lines are indented. Wraps text as needed based
on the terminal width.
Prints warning message for non-fatal issues. The first line is
prepended with 'jc: Warning - ' and subsequent lines are indented.
Wraps text as needed based on the terminal width.
Parameters:
@@ -19,15 +38,17 @@ Returns:
None - just prints output to STDERR
<a id="jc.utils.error_message"></a>
### error\_message
## error_message
```python
error_message(message_lines)
def error_message(message_lines: List[str]) -> None
```
Prints an error message for fatal issues. The first line is prepended with
'jc: Error - ' and subsequent lines are indented. Wraps text as needed based
on the terminal width.
Prints an error message for fatal issues. The first line is
prepended with 'jc: Error - ' and subsequent lines are indented.
Wraps text as needed based on the terminal width.
Parameters:
@@ -37,34 +58,43 @@ Returns:
None - just prints output to STDERR
<a id="jc.utils.compatibility"></a>
### compatibility
## compatibility
```python
compatibility(mod_name, compatible, quiet=False)
def compatibility(mod_name: str,
compatible: List,
quiet: bool = False) -> None
```
Checks for the parser's compatibility with the running OS platform.
Checks for the parser's compatibility with the running OS
platform.
Parameters:
mod_name: (string) __name__ of the calling module
mod_name: (string) __name__ of the calling module
compatible: (list) sys.platform name(s) compatible with the parser
compatible options:
linux, darwin, cygwin, win32, aix, freebsd
compatible: (list) sys.platform name(s) compatible with
the parser. compatible options:
linux, darwin, cygwin, win32, aix, freebsd
quiet: (bool) supress compatibility message if True
quiet: (bool) supress compatibility message if True
Returns:
None - just prints output to STDERR
<a id="jc.utils.has_data"></a>
### has\_data
## has_data
```python
has_data(data)
def has_data(data: str) -> bool
```
Checks if the input contains data. If there are any non-whitespace characters then return True, else return False
Checks if the input contains data. If there are any non-whitespace
characters then return True, else return False.
Parameters:
@@ -72,15 +102,57 @@ Parameters:
Returns:
Boolean True if input string (data) contains non-whitespace characters, otherwise False
Boolean True if input string (data) contains non-whitespace
characters, otherwise False
<a id="jc.utils.convert_to_int"></a>
### convert\_to\_int
## convert_to_int
```python
convert_to_int(value)
def convert_to_int(value: Union[str, float]) -> Optional[int]
```
Converts string and float input to int. Strips all non-numeric characters from strings.
Converts string and float input to int. Strips all non-numeric
characters from strings.
Parameters:
value: (string/float) Input value
Returns:
integer/None Integer if successful conversion, otherwise None
<a id="jc.utils.convert_to_float"></a>
### convert\_to\_float
```python
def convert_to_float(value: Union[str, int]) -> Optional[float]
```
Converts string and int input to float. Strips all non-numeric
characters from strings.
Parameters:
value: (string/integer) Input value
Returns:
float/None Float if successful conversion, otherwise None
<a id="jc.utils.convert_to_bool"></a>
### convert\_to\_bool
```python
def convert_to_bool(value: Union[str, int, float]) -> bool
```
Converts string, integer, or float input to boolean by checking
for 'truthy' values.
Parameters:
@@ -88,88 +160,61 @@ Parameters:
Returns:
integer/None Integer if successful conversion, otherwise None
True/False False unless a 'truthy' number or string is found
('y', 'yes', 'true', '1', 1, -1, etc.)
<a id="jc.utils.input_type_check"></a>
### input\_type\_check
## convert_to_float
```python
convert_to_float(value)
def input_type_check(data: str) -> None
```
Converts string and int input to float. Strips all non-numeric characters from strings.
Ensure input data is a string. Raises `TypeError` if not.
<a id="jc.utils.timestamp"></a>
### timestamp Objects
```python
class timestamp()
```
<a id="jc.utils.timestamp.__init__"></a>
### \_\_init\_\_
```python
def __init__(datetime_string: str,
format_hint: Union[List, Tuple, None] = None) -> None
```
Input a datetime text string of several formats and convert to a
naive or timezone-aware epoch timestamp in UTC.
Parameters:
value: (string) Input value
datetime_string (str): a string representation of a
datetime in several supported formats
Returns:
format_hint (list | tuple): an optional list of format ID
integers to instruct the timestamp object to try those
formats first in the order given. Other formats will be
tried after the format hint list is exhausted. This can
speed up timestamp conversion so several different formats
don't have to be tried in brute-force fashion.
float/None Float if successful conversion, otherwise None
Returns a timestamp object with the following attributes:
string (str): the input datetime string
## convert_to_bool
```python
convert_to_bool(value)
```
format (int | None): the format rule that was used to decode
the datetime string. None if conversion fails.
Converts string, integer, or float input to boolean by checking for 'truthy' values
naive (int | None): timestamp based on locally configured
timezone. None if conversion fails.
Parameters:
value: (string/integer/float) Input value
Returns:
True/False False unless a 'truthy' number or string is found ('y', 'yes', 'true', '1', 1, -1, etc.)
## stream_success
```python
stream_success(output_line, ignore_exceptions)
```
Add `_jc_meta` object to output line if `ignore_exceptions=True`
## stream_error
```python
stream_error(e, ignore_exceptions, line)
```
Reraise the stream exception with annotation or print an error `_jc_meta`
field if `ignore_exceptions=True`
## input_type_check
```python
input_type_check(data)
```
Ensure input data is a string
## streaming_input_type_check
```python
streaming_input_type_check(data)
```
Ensure input data is an iterable, but not a string or bytes
## streaming_line_input_type_check
```python
streaming_line_input_type_check(line)
```
Ensure each line is a string
## timestamp
```python
timestamp(datetime_string)
```
Input a date-time text string of several formats and convert to a naive or timezone-aware epoch timestamp in UTC
Parameters:
datetime_string: (str) a string representation of a date-time in several supported formats
Attributes:
string (str) the input datetime string
format (int) the format rule that was used to decode the datetime string. None if conversion fails
naive (int) timestamp based on locally configured timezone. None if conversion fails
utc (int) aware timestamp only if UTC timezone detected in datetime string. None if conversion fails
utc (int | None): aware timestamp only if UTC timezone
detected in datetime string. None if conversion fails.

Some files were not shown because too many files have changed in this diff Show More