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:56

The core usage is pretty formatting large json. I tested Chrome extension JSON View with 25MB json file. It crashes on loading this as a local file or from network. By crash, I mean JSON will not get formatted and on looking into JSON view options, you will get a crash message. I also tried similar addons for firefox. I tried online json formatters as well.

Found this library - jsonpps. Works pretty well to pretty format large json from command line, taking input and saving the formatted json as separate file. It can also save in the same file (need optional parameter)

One drawback, To install and run, one should be familier with Java and Maven.

To install & run:

git clone https://github.com/bazaarvoice/jsonpps.git
mvn clean package
cd target 
java -jar jsonpps-1.2-SNAPSHOT.jar -o /path/to/output.json /path/to/largeInput.json

This solution is not restricted to Ubuntu. It should work on any operating system.

查看更多
登录 后发表回答