Last active
January 15, 2018 15:29
-
-
Save michabbb/62d20416b92e3555c732ff13776ec70d to your computer and use it in GitHub Desktop.
Mysql - Create json date from table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
CONCAT(',\',"', c.COLUMN_NAME, '":\',', '\'"\', IFNULL(','REPLACE(TRIM(',c.COLUMN_NAME, '),\'"\',\'\\\\"\'), \'null\'),', '\'"\'') | |
FROM information_schema.COLUMNS c | |
WHERE c.TABLE_NAME = 'xxxxx'; | |
SELECT | |
CONCAT('{' | |
/* PASTE RESULT HERE AND FIX SOME MINOR COMMA STUFF */ | |
'}') | |
FROM xxxx a; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
because the mysql bash result adds an extra
\
i use sed to replace it to get a valid jsoncat sql|mysql -N your_database|sed 's/\\"/\"/g' > result.json