title: iterating json array using symfony?
body: <p>I'm trying to display a list of contract when I chose a user. So I did my query</p>
  <pre><code>    /**
   * @param $firstname
   * @param $lastname
   * @return mixed
   * @throws DBALException
   */
  public function getListPerUser($firstname, $lastname)
  {
      $em = $this-&gt;getEntityManager();
  
      $query = '
          SELECT clientname 
          FROM contact_end_client c
          INNER JOIN client_contract cli ON cli.clientname_id = c.id AND  cli.active
          INNER JOIN user u ON u.id = cli.user_id
          WHERE u.firstname = :firstname AND u.lastname = :lastname AND cli.active = 1
          ';
  
      $stmt = $em-&gt;getConnection()-&gt;prepare($query);
      $param = ['firstname' =&gt; $firstname, 'lastname' =&gt; $lastname];
      $stmt-&gt;execute($param);
      return $stmt-&gt;fetchAll();
  }
  </code></pre>
  <p>Then in my controller :</p>
  <pre><code>    /**
   * @Route(path=&quot;/newadmin/invoice/showAllContract&quot;, name=&quot;showAllContract&quot;)
   * @param Request $request
   * @return JsonResponse
   */
  public function viewContract(Request $request)
  {
      $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
      $template_id = $request-&gt;get('user');
      //dump($template_id);
      $getName = explode(&quot; &quot;, $template_id);
      $firstname = $getName[0];
      $lastname = $getName[1];
      $templateRepository = $entityManager-&gt;getRepository(ClientContract::class)-&gt;getListPerUser($firstname, $lastname);
      return new JsonResponse($templateRepository);
  }
  </code></pre>
  <p>How return me a json.
  <a href="https://i.stack.imgur.com/Cj4fc.png" rel="nofollow noreferrer">enter image description here</a>
  So I think that I have to iterate it ?
  But I have no idea how I can display this in my twig.</p>
  <pre><code>{{ form_start(createInvoice) }}
              {{ form_row(createInvoice.user) }}
              {# my contract #}
              {{ form_end(createInvoice) }}
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;script&gt;
      $(document).ready(function () {
          $('#invoice_manual_creation_user').change(function (message) {
              $('#hidden').show();
  
              let userName = $('#invoice_manual_creation_user option:selected').text();
              console.log(userName)
  
                  $.get(&quot;{{ path('showAllContract') }}&quot;, {'user': userName})
  
          });
      });
  &lt;/script&gt;
  </code></pre>