JSON Pretty-Printing

If you do any work with JSON, you may well run into scenarios where you’re looking at some data for debugging purposes, but can’t make heads or tails of it because it’s either all on one line, not indented, or otherwise simply poorly formatted.  With the upcoming RText 2.0.7 release, this will no longer be a problem.  Its “Tidy” plugin (now being rebranded to “Pretty Printing”, since it’s a more general term) is gaining JSON pretty-printing support, powered by the jsonbeans library.

You’ll be able to control the indentation style (either tabs, or some number of spaces), as well as the actual format of the output.  The format choices are:

  • JSON:  Strict adherence to the JSON standard, keys wrapped in double quotes.
  • JavaScript:  Formatting appropriate for a JavaScript object – quotes around appropriate values, but not around keys.
  • Minimal:  No double quotes around anything.  Useful if you want the data in as simple of a format as possible, even if it isn’t technically valid.

Simply set up your formatting preferences in the Pretty Printing Options dialog panel:

JSON Formatting Options

JSON Formatting Options

And when editing JSON, simply select Edit -> Pretty Printing.  Simple as that.  Don’t forget that a shortcut can be assigned to this menu item via the “Shortcuts” panel in the Options dialog if you use it frequently.

Comments are closed.