Ask HN: How do you view large JSON files?
11–20 of 60 posts
Re: Ask HN: How do you view large JSON files?
#12Re: Ask HN: How do you view large JSON files?
#13Re: Ask HN: How do you view large JSON files?
#14If not, I think I would just split data into multiple smaller files. Something like the python code below should work, assuming the file can fit in memory. If not, I assume you can find some json lib that can work in streaming mode and then do the same thing.
import json, os
json_input = '''{
"foo": 1,
"bar": 2,
"baz": 3,
"bug": 4,
"thing": 5
}'''
entries_per_group = 2
if not os.path.exists('sub_files'):
os.mkdir('sub_files')
main_d = json.loads(json_input)
iter = main_d.iteritems()
for group_count in range(10 ** 6):
sub_d = {}
try:
for _ in range(entries_per_group):
k, v = iter.next()
sub_d[k] = v
except StopIteration:
break
finally:
json_output = json.dumps(sub_d, indent=2)
with open(os.path.join('sub_files', '{}.json'.format(group_count)), 'w') as f:
f.write(json_output)Re: Ask HN: How do you view large JSON files?
#15 cat unformatted.json | python -mjson.tool | vim -
And then use vim's folding methods to navigate the file (http://vim.wikia.com/wiki/Folding)Re: Ask HN: How do you view large JSON files?
#16You could try the JSONView chrome extension.
I'm already using JSONView Chrome extension and it's great but it doesn't work with local files. Nor can I copy and paste JSON.
Re: Ask HN: How do you view large JSON files?
#17There's addons/extension for Chrome and Firefox. Both also called JSON Viewer (different author). For really large files I use a command-line tool plus grep and awk though https://stedolan.github.io/jq/
jq looks promising but I still need to view the JSON file first. I want to be able to somehow get the general understanding of the structure very quickly and interactively. The tree control works very well for that. JSON Viewer is almost perfect but it doesn't work with local files.
Re: Ask HN: How do you view large JSON files?
#18Re: Ask HN: How do you view large JSON files?
#19There's addons/extension for Chrome and Firefox. Both also called JSON Viewer (different author). For really large files I use a command-line tool plus grep and awk though https://stedolan.github.io/jq/
jq looks promising but I still need to view the JSON file first. I want to be able to somehow get the general understanding of the structure very quickly and interactively. The tree control works very well for that. JSON Viewer is almost perfect but it doesn't work with local files.
or
curl ... | jq . | less