title: Convert an Array with objects in in it into a Json
body: <p>Actually I'm working with Symfony 2.8, an I'm trying to use AJAX to get information of an id given.<br>
  This is how I use Ajax in my html.twig :<br></p>
  
  <pre><code>$.ajax({
          url: '{{ (path('questionsByAudit')) }}',
          type: "POST",
          dataType: "json",
          data: {
           "idAudit": $(this).attr('data-id')
          },
          async: true,
          success: function (data)
          {
           console.log(data);
           alert(data);
          }
        });
  </code></pre>
  
  <p>This Is my URL in my routing.yml:<br></p>
  
  <pre><code>questionsByAudit: 
      path: /QuestionsByAudit
      defaults: { _controller: FSABundle:FsaPlan/FsaPlanByAuditor:getQuestions }
  </code></pre>
  
  <p>And this is the function in the controller:<br></p>
  
  <pre><code>public function getQuestionsAction(Request $request )
      {
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
  
  
          if($request-&gt;request-&gt;get('idAudit')){
  
              $idAudit = $request-&gt;request-&gt;get('idAudit');
  
              $Audit = $em-&gt;getRepository('FSABundle:FsaAudits')
                      -&gt;findBy(array('idAudit'=&gt;$idAudit));
  
              return new JsonResponse($Audit);
          }
      }
  </code></pre>
  
  <p>THe problem is that the next function returns this:<br>
  <a href="https://i.stack.imgur.com/goa3R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/goa3R.png" alt="$Audit Result"></a>
  <br>
  And this is what I get when I print the result in an alert:<br>
  <a href="https://i.stack.imgur.com/d5w9B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d5w9B.png" alt="Result of the Ajax printed in an alert"></a></p>
  
  <p><br>
  This is what I get in console.log:<br>
  <a href="https://i.stack.imgur.com/Umqff.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Umqff.png" alt="Result in console.log"></a></p>
  
  <blockquote>
    <p><strong>NOTE:</strong> I've read that the way to return the information of the controller to the ajax call should be as a JSON, but I think that what I get in $Audit is an array with objects inside, I don't know how to return that information to the Ajax correctly.
    <br>
    <strong>Any Idea or suggestion how can I get it?</strong></p>
  </blockquote>