Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the outline of a json file

Tags:

json

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?

like image 912
Benoît Pointet Avatar asked Jan 21 '23 00:01

Benoît Pointet


2 Answers

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.

like image 115
Morten Siebuhr Avatar answered Jan 31 '23 01:01

Morten Siebuhr


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)

like image 29
Sean Patrick Floyd Avatar answered Jan 31 '23 00:01

Sean Patrick Floyd