Skip to content

Instantly share code, notes, and snippets.

@juliandunn
Last active December 31, 2015 01:29
Show Gist options
  • Save juliandunn/7914803 to your computer and use it in GitHub Desktop.
Save juliandunn/7914803 to your computer and use it in GitHub Desktop.
json gem formatting breakage

Why is the JSON output in my knife commands suddenly all on one line?

A while ago, the output from my knife commands (e.g. "knife node edit" -- which you should never use in production, by the way) changed from something like this:

{
  "name": "i-27c2205f",
  "chef_environment": "_default",
  "normal": {
    "tags": [

    ],
    "mysql": {
      "server_debian_password": "otLNhD_5jBpm1PPLGXpA",
      "server_root_password": "KGCmAbHBXSId5fMXp92r",
      "server_repl_password": "713jPVRzHLZ5woiH1Jgo",
      "root_password_set": true
    }
  },
  "run_list": [
    "role[base-windows]",
    "recipe[mysql::server]",
    "role[wordpress-server-windows]"
  ]
}

to this:

{
  "name": "i-27c2205f",
  "chef_environment": "_default",
  "normal": {"tags":[],"mysql":{"server_debian_password":"otLNhD_5jBpm1PPLGXpA","server_root_password":"KGCmAbHBXSId5fMXp92r","server_repl_password":"713jPVRzHLZ5woiH1Jgo","root_password_set":true}},
  "run_list": ["role[base-windows]","recipe[mysql::server]","role[wordpress-server-windows]"]
}

I finally tracked it down to our old friend, the Ruby JSON gem.

The many JSONs of the world

Ruby 1.9.3 comes with json 1.5.5 out of the box, and Chef will work fine with that. Chef's gemspec constraint is <= 1.7.7, > 1.4.4 and all is copacetic.

However, many tools now expect json >= 1.7.7, and if they install this Gem (or if you install it into Chef's Omnibus Ruby), Chef will happily use that version. As soon as it does, the JSON gem will start formatting all the output in a compressed way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment