mysql - Export SQL query to JSON formatted text file -


i need way run sql command , export results json formatted text file.

i have link: https://falseisnotnull.wordpress.com/2014/11/23/creating-json-documents-with-mariadb/

but don't understand create_column section of statement, nor terminology uses understand how relates db.

can please simplify example me on query this?

select * thisismy.database; 

if above outfile command, data looks this:

1     armand         warren   56045   taiwan, province of china   0        0 2      xenos    salas        71090        liberia        0                0 3      virginia   whitaker   62723   nicaragua   0                       0 4      kato patrick   97662   palau   0                       0 5      cameron      ortiz p9c5b6   eritrea 0                0 

but need this:

{ "aadata": [     [ "1", "armand", "warren", "56045", "taiwan, province of china" ],     [ "2", "xenos", "salas", "71090", "liberia" ],     [ "3", "virginia", "whitaker", "62723", "nicaragua" ],     [ "4", "kato", "patrick", "97662", "palau" ],     [ "5", "cameron", "ortiz", "p9c 5b6", "eritrea" ] ] } 

any suggestions?

thanks

edit: run mariadb if helps

select concat('[\n\t', group_concat(         column_json(             column_add(                 column_create('id', id)                 , 'name', name                 , 'price', price             )         )         order id         separator ',\n\t'     ), '\n]') json     product \g 

ignore except column_create. json creation happening. ok, have:

column_json(         column_add(             column_create('id', id)             , 'name', name             , 'price', price         )     ) 

column_add function adds columns json. each argument key paired value. 'name' key in json object , name value be. in case it's column name table product.

so, let's want query users table , first names, last names, , id. query like:

select concat('[\n\t', group_concat(         column_json(             column_add(                 column_create('id', id)                 , 'first_name', first_name                 , 'last_name', last_name             )         )         order id         separator ',\n\t'     ), '\n]') json     users \g 

and @ end of column_json command have as json, casts json type want.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -