title: How to attach cookies to JSON Response in symfony2?
body: <p>I have JSON endpoint which is used to add product to cart. It checks whether the cart already exists or no. If not then it creates a cart and the cart Id is stored in cookie. So I how do I  attach cookie to the symfony2's JsonResponse ?</p>
  
  <p>In a non ajax version if I am rendering a template from my action I can use:</p>
  
  <pre><code>$response = new Response();
  $response-&gt;headers-&gt;setCookie(new Cookie(‘cookie_name’, ‘cookie_value’));
  
  $this-&gt;render('&lt;template_path&gt;', '&lt;array_options&gt;', $response);
  </code></pre>
  
  <p>Please help me on how to do it for a JsonResponse.</p>