Tales from support: JSON code folding

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 which 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 which can be quickly executed by just pressing Ctrl-Shift-P. The sample JSON is immediately formatted in the following way:

Formatting JSON with pretty-print in JSONBuddy
Formatting JSON with pretty-print in JSONBuddy

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 as possible.