title: How to generate a JSON log from nginx?
body: <p>I'm trying to generate a JSON log from nginx.</p>
  
  <p>I'm aware of solutions like <a href="http://blog.pkhamre.com/2012/08/23/logging-to-logstash-json-format-in-nginx" rel="noreferrer">this one</a> but some of the fields I want to log include user generated input (like HTTP headers) which need to be escaped properly.</p>
  
  <p>I'm aware of the nginx changelog entries from Oct 2011 and May 2008 that say:</p>
  
  <pre><code>*) Change: now the 0x7F-0x1F characters are escaped as \xXX in an
     access_log.
  *) Change: now the 0x00-0x1F, '"' and '\' characters are escaped as \xXX
     in an access_log.
  </code></pre>
  
  <p>but this still doesn't help since <code>\xXX</code> is <a href="http://json.org/" rel="noreferrer">invalid in a JSON string</a>.</p>
  
  <p>I've also looked at <a href="http://wiki.nginx.org/HttpSetMiscModule" rel="noreferrer">the HttpSetMiscModule</a> module which has a <code>set_quote_json_str</code> directive, but this just seems to add <code>\x22</code> around the strings which doesn't help.</p>
  
  <p>Any idea for other solutions to log in JSON format from nginx?</p>