title: Can't flatten JSON array to prepare for CSV conversion using Ruby 2.1.4
body: <p>I have an array of nested JSON "hash" objects that I need to completely flatten so it ports over to CSV cleanly, which is obviously not nested and "multidimensional" like JSON typically is.</p>
  
  <p>But the flatten method (used here with ! bang) is not working (it creates the file with no error but then the file is empty).</p>
  
  <p>In my ruby file below I leave a working example of commented out code which isjust doing a simply conversion without the .flatten method. Since the JSON is an array (at the highest level) - separated by commas and enclosed in square brackets, shouldn't it take the .flatten method, just as it takes .each in the working commented out block? (This is also what the docs seems to indicate!)</p>
  
  <pre><code>require 'csv'
  require 'json'
  
  # CSV.open('false-hotels-merged.csv', 'w') do |csv|
  #   JSON.parse(File.open('monfri-false-hotels-merged.json').read).each do |hash|
  #     csv &lt;&lt; hash.values
  #   end
  # end
  
  CSV.open('wed-all-false-hotels.csv', 'w') do |csv|
    JSON.parse(File.open('monfri-false-hotels-merged.json').read).flatten! do |f|
      csv &lt;&lt; f.values
    end
  end
  </code></pre>
  
  <p>Example JSON data snippet:</p>
  
  <pre><code>[...
          {
            "id": "111707",
            "name": "Seven Park Place by William Drabble",
            "phone": "+442073161600",
            "email": "restaurant@stjameshotelandclub.com",
            "website": "http://www.stjameshotelandclub.com/michelin-star-chef-william-drabble",
            "location": {
              "latitude": 51.5062548,
              "longitude": -0.1403209,
              "address": {
                "line1": "7-8 Park Place",
                "line2": "St James's",
                "line3": "",
                "postcode": "SW1A 1LP",
                "city": "London",
                "country": "UK"
              }
            }
          },
          {
            "id": "104493",
            "name": "Seymour's Restaurant &amp; Bar",
            "phone": "+442079352010",
            "email": "reservations@theleonard.com",
            "website": "http://www.theleonard.com",
            "location": {
              "latitude": 51.51463,
              "longitude": -0.15779,
              "address": {
                "line1": "15 Seymour Street",
                "line2": "",
                "line3": "",
                "postcode": "W1H 7JW",
                "city": "London",
                "country": "UK"
              }
            }
          },
          {
            "id": "250922",
            "name": "Shaka Zulu",
            "phone": "+442033769911",
            "email": "info@shaka-zulu.com",
            "website": "http://www.shaka-zulu.com/",
            "location": {
              "latitude": 51.5414979,
              "longitude": -0.1458655,
              "address": {
                "line1": "Stables Market ",
                "line2": "Camden",
                "line3": "",
                "postcode": "NW1 8AB",
                "city": "London",
                "country": "UK"
              }
            }
          }
      ]
  </code></pre>
  
  <p>Again, no errors at all in the terminal - just blank CSV file created.</p>