 <p>I recommend the following:</p> <pre><code>require 'yaml' data = YAML.load_file '&lt;filename&gt;' data.sort_by{|hash| hash[:key1]} </code></pre> <p>Your file looks quite a bit like JSON data, but includes a few minor formatting differences that make using a JSON parser impossible. Thankfully the data is perfectly valid YAML, so Ruby's YAML parser can read it just fine.</p>