Best way to format large JSON file? (~30 mb)

JsonData Processing

Json Problem Overview


I need to format a large JSON file for readability, but every resource I've found (mostly online) doesn't deal with data say, above 1-2 MB. I need to format about 30 MB. Is there any way to do this, or any way to code something to do this?

Json Solutions


Solution 1 - Json

With python >= 2.6 you can do the following:

For Mac/Linux users:

cat ugly.json | python -mjson.tool > pretty.json

For Windows users (thanks to the comment from dnk.nitro):

type ugly.json | python -mjson.tool > pretty.json

Solution 2 - Json

jq can format or beautify a ~100MB JSON file in a few seconds:

jq '.' myLargeUnformattedFile.json > myLargeBeautifiedFile.json

The command above will beautify a single-line ~120MB file in ~10 seconds, and jq gives you a lot of json manipulation capabilities beyond simple formatting, see their tutorials.

Solution 3 - Json

jsonpps is the only one worked for me (https://github.com/bazaarvoice/jsonpps).<br/> It doesn't load everything to RAM unlike jq, jsonpp and others that I tried.

Some useful tips regarding installation and usage:

Download url: https://repo1.maven.org/maven2/com/bazaarvoice/jsonpps/jsonpps/1.1/jsonpps-1.1.jar

Shortcut (for Windows):

  1. Create file jsonpps.cmd in the same directory with the following content:
    @echo off java -Xms64m -Xmx64m -jar %~dp0\jsonpps-1.1.jar %*

Shortcut usage examples:

  1. Format stdin to stdout:
    echo { "x": 1 } | jsonpps
  2. Format stdin to file
    echo { "x": 1 } | jsonpps -o output.json
  3. Format file to file:
    jsonpps input.json -o output.json

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncovarianceView Question on Stackoverflow
Solution 1 - JsonpstadlerView Answer on Stackoverflow
Solution 2 - JsonjmngView Answer on Stackoverflow
Solution 3 - Jsonnicolas2008View Answer on Stackoverflow