Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created May 18, 2014 18:52
Show Gist options
  • Save meeuw/397d119543166cca8ee2 to your computer and use it in GitHub Desktop.
Save meeuw/397d119543166cca8ee2 to your computer and use it in GitHub Desktop.
generate json dump from mysqldump
#!/usr/bin/python
import fileinput
import json
output = {}
for line in fileinput.input():
if line.startswith('CREATE TABLE'):
table = line.split('`')[1]
if line.startswith(' `'):
if not table in output: output[table] = {}
s = line[2:].split('`')
output[table][s[1]] = s[2][:-2]
print json.dumps(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment