How to see a large JSON file pretty printed on Ubu

2020-05-22 15:33发布

I would like to hear your suggestions on how to handle a large (40MB) JSON file on Ubuntu. I would like to see it pretty printed in vim or gedit or any other editor. One can find numerious tutorials on how to prettify the JSON, however, they do not have to deal with large input. I also imagine I could pipe the data through pygments or any other syntax highlighter. I am curious to hearing your ideas.

Example download:

wget -O large-dataset.json http://data.wien.gv.at/daten/wfs?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:BAUMOGD&srsName=EPSG:4326&outputFormat=json

Please mind the download size!


EDIT: I found out that meld is working somewhat. The application does not load the whole file at once which would block the user interface. Instead it sequentially reads the file content.

7条回答
劫难
2楼-- · 2020-05-22 15:34

Python JSON's module can do this too (python -m json.tool), e.g.:

cat myjsonfile.json | python -m json.tool > pretty.json
查看更多
劫难
3楼-- · 2020-05-22 15:39

If you just want to visualize (and search) a json file, Firefox does a pretty good job. I don't have a 40MB file on hand, but it easily handled a 9MB one.

Just drag the JSON file to Firefox, or run:

firefox your_file.json

查看更多
姐就是有狂的资本
4楼-- · 2020-05-22 15:40

Do you have KDE or any other visual environment? If yes, have you tried using the chrome extension JSONView?

查看更多
beautiful°
5楼-- · 2020-05-22 15:51

jq is a lightweight commandline JSON processor and works well! for this you need to install jq with the command below(if you are using apt package manager).

sudo apt-get install jq

Below command will pretty json to a new file.

 jq '.' non-pretty.json > pretty.json

Also we can filter the json with jq, I found it to be very helpful while working with large geojson files, for instance below command will save only properties of first feature.

jq '.features[0].properties' geojson_file.json > pretty.json

Hope this will be helpful!

查看更多
看我几分像从前
7楼-- · 2020-05-22 15:52

I usually use Sublime Text for this purpose. There is a dedicated plugin for this job.

The plugin Pretty JSON parses the JSON contents selected, and prints them in a structured way.

All you need to do is to select the contents and press Ctrl+Alt+j.

查看更多
登录 后发表回答