Getting the outline of a json file
I have to deal with JSON files larger than 1MB, which often contain long arrays and are of unknown structure.
How do I out开发者_Go百科line those JSON files so that I get an overview of their structure and peaks at some of the values?
You generally can't; the way JSON is structured, you will have to parse all of it, to figure out the overall structure (and see if it is even valid JSON). All in all, you can just as well introspect it in it's entirety, once you're at it.
As you don't specify a language, I'll have a go at it in Python:
import json
import pprint
data = json.load(open('filename.json', 'rb'))
pprint.pprint(data, depth=2)
Should pretty-print the first two levels of your JSON document.
Google JSON formatter
and you'll find several online solutions. The first looks promising to me:
JSON Formatter (& Validator)
(It lets you define different output templates and it even validates the structure)
Update: here's another one that does exactly what you want:
Collapsible JSON Formatter
(It lets you define exactly which levels you want to expand and collapse)
精彩评论