Live data from Hacker News

Ask HN: How do you view large JSON files?

news.ycombinator.com

11–20 of 60 posts

Re: Ask HN: How do you view large JSON files?

#14
I think Sublime Text should be able to handle fairly large json files without a problem.

If 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?

#16
post #6

You 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.

Why not just throw the file(s) up on a box somewhere so you can use it, or host it locally, can you not use locally hosted links with it or something?

Re: Ask HN: How do you view large JSON files?

#17
post #3

There'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.

jq . file.json | less

Re: Ask HN: How do you view large JSON files?

#19
post #3

There'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.

jq . file.json | less

or

curl ... | jq . | less

Post reply on HN