Created
September 5, 2017 17:51
-
-
Save jones77/db08ce9465712bd9f01a5be6fd570d28 to your computer and use it in GitHub Desktop.
Flatten json to csv
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # usage: json2csv url | |
| # requirements: requests, flatten_json | |
| # ie use pip or pip2 and install them: | |
| # sudo pip (or sudo pip2) install requests flatten_json | |
| import sys | |
| from flatten_json import flatten | |
| import requests | |
| if __name__ == '__main__': | |
| r = requests.get(sys.argv[1]) | |
| d = r.json() | |
| f = flatten(d) | |
| # FIXME: escape quotes? | |
| # Headings | |
| print("{}".format(','.join(f.keys()))) | |
| # Values | |
| print("{}".format(','.join(f.values()))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment