Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reflexe/convert_table_to_json
Convert text tables to JSON document
https://github.com/reflexe/convert_table_to_json
command json json-document python tables text text-processing
Last synced: 6 days ago
JSON representation
Convert text tables to JSON document
- Host: GitHub
- URL: https://github.com/reflexe/convert_table_to_json
- Owner: Reflexe
- License: mit
- Created: 2016-10-28T12:16:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-16T19:53:33.000Z (about 7 years ago)
- Last Synced: 2023-07-02T04:23:19.071Z (over 1 year ago)
- Topics: command, json, json-document, python, tables, text, text-processing
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 7
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
## Table To Json
Convert text tables to a json document.## Usage
```$ ./convert_to_json.py (index=[name],...) (file,...) --delim=delim[:min[-max]],...```* *index*: the table column index to print, begins from 0. Can be combined with '=' to
define a name for this index. If equal to '\*', all indexes will be accepted
(you can combine '\*' with regular indexes).* *file*: one or more file names to read from. The default is stdin.
* *delim*: One or more string delimiter of the table seperated by comma (,). Can be combined be ':' and
a minimum delimiter repeat count, and (optional) '-' and maximum delimiter repeat count. The default minimum
number is 1, the default maximum number is infinite.## Examples
Parse a CSV [file](https://github.com/Reflexe/convert_table_to_json/blob/master/Data/example.csv):
```
$ ./convert_to_json.py '0=Name,1=UserName,3=Phone' Data/names.csv --delim='\,'
[{"Phone": "1234", "UserName": "Jim1", "Name": "Jimmy"}, {"Phone": "0000", "UserName": "TheHacker^", "Name": "John"}, {"Phone": "1111", "UserName": "r00x", "Name": "Jack"}]
```
Parse the linux `ss` command output and get the currently open tcp sessions:
```
$ ss --tcp | ./convert_to_json.py '0=State,3=LocalAddressPort,4=RemoteAddrPort'
[{"State": "ESTAB", "LocalAddressPort": "10.0.0.2:42554", "RemoteAddrPort": "x.x.x.x:https"}]
```### Have fun! :smile: