title: Exporting Postgres Rows as a JSON File
body: <p>I need to generate a JSON file for a dataTables section on my web site. The format of the JSON should look like this:</p>
  
  <pre><code>{
          "data": [
                  [
                          "Tiger Nixon",
                          "System Architect",
                          "Edinburgh",
                          "5421",
                          "2011/04/25",
                          "$320,800",
                  ],
                  [
                          "Garrett Winters",
                          "Accountant",
                          "Tokyo",
                          "8422",
                          "2011/07/25",
                          "$170,750"
                  ],
          ]
  }
  </code></pre>
  
  <p>This format looks like an array of arrays listed on the <a href="https://www.postgresql.org/docs/current/static/functions-json.html#FUNCTIONS-JSON-CREATION-TABLE" rel="nofollow">JSON Creation Functions (Table 9-42.)</a> -- array_to_json.</p>
  
  <p>However, my data is not stored as arrays in my database.  It's typical row data.</p>
  
  <p>But when I try to export to JSON using "row_to_json" -- the format is way off from what I need.  <a href="http://sqlfiddle.com/#!15/9b641/1" rel="nofollow">See this SQLfiddle example.</a></p>
  
  <p>Basically, I'm trying to figure out the best approach to make the JSON export look more like the format pasted above.</p>
  
  <p>Should I be reformatting my rows into arrays first, and storing them in a new table, so when I use "row_to_json" they come out as arrays?  Or is there a better way?</p>