mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
2.3 KiB
2.3 KiB
jc.parsers.asciitable
jc - JSON Convert asciitable
parser
This parser converts ASCII and Unicode text tables with single-line rows.
Column headers must be at least two spaces apart from each other and must be unique.
For example:
╒══════════╤═════════╤════════╕
│ foo │ bar │ baz │
╞══════════╪═════════╪════════╡
│ good day │ │ 12345 │
├──────────┼─────────┼────────┤
│ hi there │ abc def │ 3.14 │
╘══════════╧═════════╧════════╛
or
+-----------------------------+
| foo bar baz |
+-----------------------------+
| good day 12345 |
| hi there abc def 3.14 |
+-----------------------------+
or
| foo | bar | baz |
|----------|---------|--------|
| good day | | 12345 |
| hi there | abc def | 3.14 |
or
foo bar baz
--------- -------- ------
good day 12345
hi there abc def
etc.
Usage (cli):
$ cat table.txt | jc --asciitable
Usage (module):
import jc
result = jc.parse('asciitable', asciitable_string)
Schema:
[
{
"column_name1": string, # empty string is null
"column_name2": string # empty string is null
}
]
Examples:
$ asciitable | jc --asciitable -p
[]
$ asciitable | jc --asciitable -p -r
[]
parse
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, cygwin, win32, aix, freebsd
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)