简体   繁体   中英

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 outline 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM