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.
So, I got this message not too long ago from a new user of JSONBuddy.
The user wrote: “Trying to read log files generated with NLog in Json format. JSONBuddy JSON editor complaining about format. Example data from file: { … some sample data… }”
Apparently, the user, let’s call him John to make this sound less “robotic”, was experiencing issues with reading a JSON log file generated with NLog and he was curious if JSONBuddy can help as a mature JSON editor.
Use JSONBuddy to open your log data
First things first, JSONBuddy wholly and thoroughly supports log files presented in JSON format and unsurprisingly so. Asides from being readily readable in your JSON editor, a trait not so many other log formats can boast of having, the JSON data format shines outstandingly in that it presents data in a reasonably compact and heavily structured form.
What this means is that your log files gains attributes typically associated with big data – it is layered as you would find in traditional database architectures and finely structured to make querying, analytics, or troubleshooting less of a hassle than it normally is.
So back to John now. His issue was essentially down to the fact that JSONBuddy was having a hard time recognizing the log file he was browsing in the JSON editor. And that’s because JSON supports an increasingly wide array of data structures including but not limited to Objects, Arrays, Strings, and Values. Each data structure has its peculiarities and as such, is handled differently by the JSONBuddy editor.
Convert a sequence of JSON objects into a valid array
To make headway, all John had to do was point JSONBuddy to the data structure inherent in the NLog derived log file. In his case, the log files was a sequence of JSON objects, and that meant using the “Surround with JSON array” command is the thing to do. One click and voila, JSONBuddy came to terms with the input before proceeding to accurately render it in the JSON editor.
The command will format the current selection or the whole document if no selection is set. You will get a well-formed JSON array afterward in the editor window and you can pretty-print it using Ctrl-Shift-p. Moreover, you can also open the log in the Grid window.
I simply sent John a message explaining those steps, and a few minutes later, I got an affirmative “Thank you” as a reply. One more happy client!
A user sent me an inquiry about opening large JSON data in JSONBuddy. This can be indeed a little bit tricky if the default view for JSON data is set to the Grid view in the editor settings. Not all data is suitable to be displayed in the Grid view. JSON with a lot of child properties at the same parent could take a lot of processing time and memory if you want to show the JSON as Grid in the editor. So the user wanted to get some help:
I don’t believe this is a fault in your software, as all other editors seem to be overwhelmed by the 450,000 rows as well… I was just curious if you had any tips that may help improve the performance of this application…. As without better performance, I cannot justify purchasing a license.
And I replied:
450,000 rows in total is not that much as I’m frequently working with files with several millions of lines. I recommend to use the text view modes of JSONBuddy (and XML ValidatorBuddy) if you are working with really large files. Using the text view, the editor supports two modes. The standard view which loads all of the file content and the Large File view which always only keeps parts of the content in memory.
Set the default view to text for large data
As a first step set the text view as the default view for your large (JSON, XML or any text format) data. Please learn more about this here.
Set a limit in MB for the Large File text view in the editor
How can you set the limit for the Large File view? There is a setting in the Options dialog on the Editor page which sets the limit in megabytes for using the standard view:
Any file larger than the limit will be loaded in the Large File view. Using the Large File view it is no problem to browse files even with a size of several GBs. Please note that you would need a plus license of XML ValidatorBuddy (a Plus version of JSONBuddy with support for large file editing will be available in the near future) if you want to edit the file. In general, avoid the Grid view for large data and use the Large File view in the text editor.
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.