What do you do if you need to compact a JSON document but the file has more than 400 MB and 20 Million lines? Or the other way around, you have a large document and it is impossible to read because it has no formatting? So you need a JSON editor which can do two things for you. The editor can open and view really large text files and it needs to know how to format or compact your JSON data. Luckily, JSONBuddy can do both for you.
Simply select your large JSON document in the built-in File Explorer window. You can also select multiple files if you need to do this for several documents:
Run either the “Pretty-print JSON” or “Remove whitespace from JSON” command from the JSON menu. JSONBuddy will save the output document next to the original JSON with a new file name. You will still have the original content as before on your disk.
Of course, you can run both commands on the current document in the JSON editor.
Maybe, you often have to deal with JSON data which is not formatted as you like or has no white space at all. As an example, it is hard to edit this JSON text in the editor:
What you need is an editor that a) understands the JSON syntax and b) can quickly format your JSON data hassle-free.
Format JSON data with no white space in the editor
In JSONBuddy, just use the pretty-print feature to format the current text content at any time. The keyboard shortcut for the pretty-print command is Ctrl+Shift+p (you can change the shortcut in the “Options…” dialog). There is also a menu item at “JSON | Pretty-print JSON”. After the formatting the JSON data is much more readable and can be easily modified in the editor:
Note that short array content is aligned at a single line (available with JSONBuddy 5). This makes the JSON more compact and is saving space in the editor window. This is also true for arrays with only primitive types and having no long string values. As a consequence, arrays with many items of only primitive types, often numbers, are still displayed in a compact way with no new-lines separating the single items. In contrast, arrays with long string values are displayed with each item on a new line to increase readability. The editor applies an adaptive JSON formatting based on the actual content.
Use pretty-print in combination with the navigation history
The pretty-print functionality is getting even more powerful in combination with the navigation history of the JSON editor. If you format your JSON data while you are adding new properties, objects or arrays, the navigation history sets the text selection to the current property, after you applied the formatting operation.
You can also use the “Navigate Backward Ctrl+Shift+,” and “Navigate Forward Ctrl+Shift+.” commands to navigate through the selection history as you need.
Someone who set “Recommend: yes” and “Overall quality: 1” (best) on the survey form sent the additional following feedback:
Code folding for JSON file does not work for situations like: “RaceCar”: { “Domestic”: true, “Model”: [] }
Unfortunately, the user did not provide an email address so I couldn’t get in contact with her/him. So what is the JSON editor doing with JSON data like this in terms of code folding? The sample data is all in one line. There is actually no chance for the editor to show code folding for JSON content that spans over a single line.
Use JSON pretty-print to show code folding
However, if you are using JSONBuddy as your JSON editor you also get a very useful pretty-print functionality that can be quickly executed by just pressing Ctrl-Shift-P. The sample JSON is immediately formatted in the following way:
As you can see, folding is available after the JSON data is formatted in the editor. It is also convenient that the current selection is also preserved after the pretty-print operation is completed. Maybe a small but important detail to provide the best JSON editor experience possible.
What do you do if you need to compact a JSON document but the file has more than 400 MB and 20 Million lines? Or the other way around, you have a large document and it is impossible to read because it has no formatting? So you need a JSON editor which can do two things for you. The editor can open and view really large text files and it needs to know how to format or compact your JSON data. Luckily, JSONBuddy can do both for you.
Select your large JSON data
Simply select your large JSON document in the built-in File Explorer window. This is important to avoid loading the file into the editor and to keep a constant memory footprint for really huge JSON documents. You can also select multiple files if you need to do this for several documents:
Remove whitespace from your large JSON documents
Run either the “Pretty-print JSON” or “Remove whitespace from JSON” command from the JSON menu. JSONBuddy will save the output document next to the original JSON with a new file name. You will still have the original content as before on your disk.
Of course, you can also run both commands on the current document in the JSON editor.