title: How to output sorted hash in ruby template
body: <p>I'm building a config file for one of our inline apps. Its essentially a json file. I'm having a lot of trouble getting puppet/ruby 1.8 to output the hash/json the same way each time.</p>
  
  <p>I'm currently using </p>
  
  <pre><code>&lt;%= require "json"; JSON.pretty_generate data %&gt;
  </code></pre>
  
  <p>But while outputting human readable content, it doesn't guarantee the same order each time. Which means that puppet will send out change notifications often for the same data.</p>
  
  <p>I've also tried</p>
  
  <pre><code>&lt;%= require "json"; JSON.pretty_generate Hash[*data.sort.flatten] %&gt;
  </code></pre>
  
  <p>Which will generate the same data/order each time. The problem comes when data has a nested array.</p>
  
  <pre><code>data =&gt; { beanstalkd =&gt; [ "server1", ] }
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>"beanstalkd": "server1",
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>"beanstalkd": ["server1"],
  </code></pre>
  
  <p>I've been fighting with this for a few days on and off now, so would like some help</p>