title: Format query result as JSON in Athena
body: <p>In Athena, I have some data in formatted as a rather complicated struct with various nested arrays and structs:</p>
  
  <pre><code>struct&lt;a:struct&lt;b:string, c:int, d:array&lt; ... &gt;&gt;&gt;
  </code></pre>
  
  <p>I want to format my query result as a JSON string:</p>
  
  <pre><code>{"a": {"b": "cow", "c": 5, "d": [ ... ]}}
  </code></pre>
  
  <p>However if I cast the data to JSON, <code>CAST(x AS JSON)</code>, I just get the associated values:</p>
  
  <pre><code>[["cow", 5, [ ... ]]] 
  </code></pre>
  
  <p>How do I get the desired format without constructing the JSON object by hand? The underlying data in the S3 bucket is JSON; is there a better way to format the table in Athena?</p>