title: How to pass JSON data to rest API in symfony2
body: <p>I am creating rest api for symfony 2,but not able to pass JSON data to post method. <code>$userform-&gt;isValid()</code>always failed.</p>
  
  <pre><code>curl -v -H "Accept: application/json" -X POST -d '{"username":"hitesh","userpassword":"hitesh123"}' http://localhost/us/serenify/web/app_dev.php/user/login
  </code></pre>
  
  <p>This is the data I am passing for test purpose.</p>
  
  <pre><code>  public function loginAction(Request $request)
      {
           return $this-&gt;processForm(new User(),$request);
      }
  
  
  
   private function processForm(User $user,$request)
      {   
          $userform = $this-&gt;createForm(new UserType(), $user);       
          $content = $this-&gt;getRequest();              
          $userform-&gt;submit($content);
         $key = md5(microtime().rand());
              if ($userform-&gt;isValid()) 
              {
  
                  if(trim($data['username'])=="" || trim($data['userpassword']==""))
                  { 
                         $data=array(
                                  "success"=&gt;'false',
                                  "msg"=&gt;'username or password is blank'    
                              );
                          $response = new Response(json_encode($data));
                          $response-&gt;setStatusCode(203);
                          $response-&gt;headers-&gt;set('Content-Type', 'application/json'); 
                  }
                  else
                  {   
                      $username=trim($data['username']);
                      $userpassword=trim(md5($data['userpassword']));
  
                      $user = $this-&gt;getDoctrine()
                                         -&gt;getRepository('SerenifyUserBundle:User')
                                         -&gt;findOneBy(array('username' =&gt; $username, 'userpassword' =&gt; $userpassword));
                      if (!$user)
                      {
                          $data=array(
                                  "success"=&gt;'false',
                                  "msg"=&gt;'username or password is wrong'    
                              );
                          $response = new Response(json_encode($data));
                          $response-&gt;setStatusCode(404);
                          $response-&gt;headers-&gt;set('Content-Type', 'application/json');     
                      }
                      else
                      {
                           $data=array(
                                  "success"=&gt;'true',
                                  "msg"=&gt;'user has sucessfully logged in',
                                  "username" =&gt; $username,
                                  "sessionis" =&gt; $key,
  
                              );
                          $response = new Response(json_encode($data));
                          $response-&gt;setStatusCode(404);
                          $response-&gt;headers-&gt;set('Content-Type', 'application/json');  
                      }
                       $response = new Response(json_encode($data));    
                  }
              }
              else
              {
                  $data=array(
                                  "success"=&gt;'false',
                                  "msg"=&gt;'invalid form content'    
                              );
                          $response = new Response(json_encode($data));
                          $response-&gt;setStatusCode(404);
                          $response-&gt;headers-&gt;set('Content-Type', 'application/json');  
  
               }
          return $response;
      }
  </code></pre>
  
  <p>Above is my controller code.</p>
  
  <p>When I print request value is does not show in JSON format.</p>
  
  <p>Anyway to test or pass JSON data? I am creating login functionality.</p>