title: Rails converts empty arrays into nils in params of the request
body: <p>I have a Backbone model in my app which is not a typical flat object, it's a large nested object and we store the nested parts in TEXT columns in a MySQL database.</p>
  
  <p>I wanted to handle the JSON encoding/decoding in Rails API so that from outside it looks like you can POST/GET this one large nested JSON object even if parts of it are stored as stringified JSON text.</p>
  
  <p>However, I ran into an issue where Rails magically converts empty arrays to <code>nil</code> values. For example, if I POST this:</p>
  
  <pre><code>{
    name: "foo",
    surname: "bar",
    nested_json: {
      complicated: []
    }
  }
  </code></pre>
  
  <p>My Rails controller sees this:</p>
  
  <pre><code>{
    :name =&gt; "foo",
    :surname =&gt; "bar",
    :nested_json =&gt; {
      :complicated =&gt; nil
    }
  }
  </code></pre>
  
  <p>And so my JSON data has been altered..</p>
  
  <p>Has anyone run into this issue before? Why would Rails be modifying my POST data?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here is where they do it:</p>
  
  <p><a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/request.rb#L288">https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/request.rb#L288</a></p>
  
  <p>And here is ~why they do it:</p>
  
  <p><a href="https://github.com/rails/rails/pull/8862">https://github.com/rails/rails/pull/8862</a></p>
  
  <p>So now the question is, how to best deal with this in my nested JSON API situation?</p>