Created
January 6, 2017 22:14
-
-
Save alexpreynolds/b4ef738d8838af5f770e40091a96548b to your computer and use it in GitHub Desktop.
Convert JSON string to tab-delimited output
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 python | |
import sys | |
import json | |
test_json_str = ''' | |
[ | |
{"name":"FOO", "chr":"chrN", "start":100, "stop":200}, | |
{"name":"BAR", "chr":"chrN", "start":300, "stop":400}, | |
{"name":"BAZ", "chr":"chrN", "start":700, "stop":750} | |
] | |
'''.strip() | |
test_json_obj = json.loads(test_json_str) | |
for gene_obj in test_json_obj: | |
line = '\t'.join([gene_obj["chr"], | |
str(gene_obj["start"]), | |
str(gene_obj["stop"]), | |
gene_obj["name"]]) | |
sys.stdout.write("%s\n" % line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment