rjson – readable JSON

[Edited: after some feedback, I have renamed this project to rjson (it’s really not at all Go-specific) and changed the specification so that unquoted strings are accepted only as object keys]

JSON is a fine encoding. It has a very simple data model; it’s easy to understand and to write parsers for.  But personally, I find it a bit awkward to read and to edit. All those quotes add noise, and I’m always forgetting to remove the final comma at the end of an array or an object. I’m not the only one either. I’ve chatted to people about why they are using YAML, and the reason is usually not because of the zillion features that YAML offers, but because the format is more human-friendly to edit.

A while ago I had an idea of how I might help this, and yesterday I had a free day to do it. I forked the Go json package to make rjson. It uses an idea taken from the Go syntax rules to make commas optional, and quotes become optional around object keys that look like identifiers. The rjson syntax rules are summarised in the rjson package documentation.

To make it easy to experiment with and use this format, I created a rjson command that can read and write both formats.

Here is a transcript showing how the command can be used:

% cat config.json
  "ui" : {
    "global" : {
      "ui-type" : "default",
      "show-indicator" : true
}% rjson < config.json
	ui: {
		global: {
			show-indicator: true
			ui-type: "default"
% rjson -indent '' < config.json
% rjson -indent '' -j < config.json

You might notice that the compact version of the rjson format is smaller than the equivalent JSON. On a random selection of JSON files (all that I could find in my home directory), I measured that they were about 7% smaller on average when encoded with gson -indent ”. This was a nice bonus that I had not considered.

To use rjson, you’ll need a working Go installation; then you can fetch and install the command into your go tree thus:

go get launchpad.net/rjson/cmd/rjson


3 Responses to “rjson – readable JSON”

  1. Andre Says:

    goson = json meets yaml.

    it’s incredible how the removal of some double-quotes makes things more readable.

  2. Michael Schurter (@schmichael) Says:

    “python -m json.tool” is a more verbose to type but available by default on most non-Windows systems. It doesn’t have any options for indentation though.

  3. Tobia Says:

    This is pretty interesting and should be very useful as a config file format.

    Do you plan to add support for Javascript-like comments? Both //… and /*…*/ would be very useful in a configuration file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: