Created
June 14, 2014 04:46
-
-
Save nemith/1182437e248b8b69d17a to your computer and use it in GitHub Desktop.
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
| import json | |
| import csv | |
| import cStringIO | |
| JSON = ''' | |
| {"items": [ | |
| {"name": "Test One", "integer": 45}, | |
| {"name": "Test Two", "integer": 76}, | |
| {"name": "Test Three", "integer": 42} | |
| ] | |
| } | |
| ''' | |
| data = json.loads(JSON) | |
| items = data['items'] | |
| output = cStringIO.StringIO() | |
| writer = csv.DictWriter(output, items[0].keys()) | |
| writer.writeheader() | |
| for row in items: | |
| writer.writerow(row) | |
| print output.getvalue() |
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
| bbennett@annav-t420s:~<1>$ python jsontest.py | |
| integer,name | |
| 45,Test One | |
| 76,Test Two | |
| 42,Test Three |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment