Comments - mysql Command-line Client
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
How about adding -J (or --json) flag to extract json output of a SQL using mysql client. [just like -X or -H options]
Example: Here below, I'm extracting using 2 step process (using sed). It would be great if we can handle this using C and some good JSON parser.
Create a small bash script named tojson: --
sed -e 's/\t/\",\"/g' \ -e 's/^/\[\"/' \ -e 's/$/\"\],/' \ -e '1s/\(.*\)/\{\"fields\":\1\ \"data\":[/g' -e '$s/.$/\]\}/' \
--
To execute:
mysql -u<dbuser> -p<dbpass> -S<socket-path> -D<dbname> -X -e "SQL-STATEMENT" | ./tojson
Now a days JSON parsers are widely used and has lots of benefits over XML.