# Deserialize JSON post body

**URL:** <https://www.ruby-forum.com/t/deserialize-json-post-body/126603>\
**Category:** Rails\
**Created:** [January 20, 2008, 5:47am UTC](https://www.ruby-forum.com/t/deserialize-json-post-body/126603 "2008-01-20T05:47:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [January 20, 2008, 5:47am UTC](https://www.ruby-forum.com/t/deserialize-json-post-body/126603/1 "2008-01-20T05:47:59Z")

</div>

I’m doing an HTTP post to my controller with an xml request body:

curl -u 53b2c:X -H “Content-Type: text/xml” -v -d  
“\<full\_name\>Alex E.\</full\_name\>\<carrier\_id\>2\</  
carrier\_id\>\<mobile\_phone\>1234321843\</mobile\_phone\>asdf\</  
password\>\<sub\_categories type="array"\>\<sub\_category\>1\</  
sub\_category\>\<sub\_category\>2\</sub\_category\>\</sub\_categories\>\</  
subscriber\>” [http://localhost:3000/subscribers/helper.xml](http://localhost:3000/subscribers/helper.xml)

Rails deserialized xml xml into a subscriber hash:

Parameters: {“subscriber”=\>{“carrier\_id”=\>“2”, “sub\_categories”=\>[“1”,  
“a”], “full\_name”=\>“Alex E.”, “password”=\>“asdf”,  
“mobile\_phone”=\>“1234321843”}, “format”=\>“xml”, “action”=\>“helper”,  
“controller”=\>“subscribers”}

However, if I do the same post with a JSON body, it fails to find  
anything in the body:

curl -u 53b2c:X -H “Content-Type: application/json” -v -d  
‘{“subscriber”:{“carrier\_id”:2, “full\_name”:“alex egg”,  
“mobile\_phone”:“7605554311”, “password”:“asdf”, “sub\_categories”:  
[1,2]}}’ [http://localhost:3000/subscribers/helper.json](http://localhost:3000/subscribers/helper.json)

Parameters: {“format”=\>“json”, “action”=\>“helper”,  
“controller”=\>“subscribers”}

And I get this back in the response:

[[“carrier\_id”, “can’t be blank”], [“full\_name”, “can’t be blank”],  
[“mobile\_phone”, “can’t be blank”], [“mobile\_phone”, “is too short  
(minimum is 10 characters)”]]

Shouldn’t rails be able to deserialize the JSON body?
