title: JSON::ParserError: A JSON text must at least contain two octets! (for non-nil input)
body: <p>So, I realize <a href="https://stackoverflow.com/questions/8390256/a-json-text-must-at-least-contain-two-octets">two</a> <a href="https://stackoverflow.com/questions/7200554/what-is-json-octet-and-why-are-two-required">questions</a> have already been asked on this subject, but (unfortunately) my case appears to be different.</p>
  
  <p>The <a href="http://www.sinatrarb.com/intro.html" rel="nofollow noreferrer">Sinatra README</a> says to do the following for POST data:</p>
  
  <pre><code>post "/api" do
    request.body.rewind  # in case someone already read it
    data = JSON.parse request.body.read
    "Hello #{data['name']}!"
  end
  </code></pre>
  
  <p>When I try this, I get:</p>
  
  <pre><code>JSON::ParserError: A JSON text must at least contain two octets!
  </code></pre>
  
  <p>The other questions deal with a case in which the data is nil, or poorly formatted (<code>\"</code> instead of <code>"</code>), but mine appears to be good. If I open irb and JSON.parse the exact same string that I'm POSTing, it works just fine.</p>
  
  <p>This is the command I'm using for testing:</p>
  
  <pre><code>curl -XPOST http://localhost:5000/endpoint --data '{"foo":"bar","blah":"wat","abcdefghijklmnop":"qrstuvwxyz"}'
  </code></pre>
  
  <p>I feel like this should be insanely obvious, because parsing POST data is a really basic thing for a webserver to do. Apparently not though.</p>
  
  <p><strong>Edit:</strong> If I call <code>logger.info Hash[params]</code>, I get:</p>
  
  <pre><code>{"{\"foo\":\"bar\",\"blah\":\"wat\",\"abcdefghijklmnop\":\"qrstuvwxyz\"}"=&gt;nil,   "splat"=&gt;[], "captures"=&gt;["endpoint"], "resource"=&gt;"endpoint"}
  </code></pre>
  
  <p>...but I'm not sure if/how that helps.</p>