Q:

rack application, params as key

I'm requesting rack application with
curl -X POST -d '{"device":{"username":"123456","name":"some name","location":"Hidden"}}' http://localhost:9292/device

In the rack application I'm creating request object
request = Rack::Request.new(env)

And I'm expecting that POST data will be in params hash
request.params => should be a normal hash

but somehow it's not quite correct. I got params in this format
{{"device":{"username":"123456","name":"some name","location":"Hidden"}}=>nil}

So the params data which I needed became a key of hash. Why is that and how to make it normalhash like this
{"device":{"username":"123456","name":"some name","location":"Hidden"}}

? Thanks

A:

normally -d expects data to be passed in var=val format, and as you did not pass var it transforms your data to var and assign a empty string to it.
when you using curl like this you get following params:
 params = {'{"device":{"username":"123456","name":"some name","location":"Hidden"}}'=>nil}

then you simply parse it as json:
require 'json'

JSON.parse params.keys.first    
=> {"device"=>{"username"=>"123456", "name"=>"some name", "location"=>"Hidden"}}

alternatively you can pass params like this:
curl -X POST -d 'json={"device":{"username":"123456","name":"some name","location":"Hidden"}}' :9292

then you get following params:
params = {'json'=>'{"device":{"username":"123456","name":"some name","location":"Hidden"}}'}

and simply parse into JSON:
JSON.parse(params['json'])

#=> {"device"=>{"username"=>"123456", "name"=>"some name", "location"=>"Hidden"}}

