convert mysql query table formatted output to json/yaml array
Project description
convert mysql query output (in table format) to json or yaml
Summary
We will take as input mysql query output, then convert that to an array of the records in yaml or json format, using the ‘header’ line from the query as the tags for each of the fields.
Usage
usage: tbltojson.py [-h] [-p] [-t {json,yaml}] [-l {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [-s] [file]] yaml json k8s laundry positional arguments: files optional arguments: -h, --help show this help message and exit -p, --pretty -t {json,yaml}, --type {json,yaml} Output type, json or yaml -l {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --loglevel {DEBUG,INFO,WARNING,ERROR,CRITICAL} Log level (DEBUG,INFO,WARNING,ERROR,CRITICAL) default is: INFO -s, --save save select command line arguments (default is always) in "/home/gfausak/.tbltojson.conf" file tbltojson pod.yaml service.yaml replicationcontroller.yaml > /tmp/bigfile.yaml
Arguments
–pretty, make the output (json) pretty. yaml is already pretty. default is false.
–help, the usage message is printed.
–type, json or yaml (this is the OUTPUT type, input can be either), default yaml.
—loglevel, for debugging, default INFO.
–save, save current arguments to persistent file in home directory, this file will be read as if it came from the command line in subsequent invocations of this program. To remove it you have to remove the ~/.tbltojson.conf file manually. Do this for making pretty default, for example. the default is no save is done.
file, the file to convert. stdin used if file not specified.
Examples
A lot of the openstack output comes in mysql format, not too useful in scripts.
tbltojson mysqlqueryoutput.txt -t json tbltojson mysqlqueryoutput.txt -t json -p tbltojson mysqlqueryoutput.txt -t yaml