title: Twig json_encode with entity objects and collections (Symfony3)
body: <p>From my controller I pass an <strong>array of entities</strong> called <code>Tag</code> to the twig file like this:</p>
  
  <pre><code>return $this-&gt;render('tags/list.html.twig', array(
      'tags' =&gt; $tags,
  ));
  </code></pre>
  
  <p>Then, I show each tag in HTML with Twig <code>for</code>. Each <code>Tag</code> has a collection of entity <code>Texts</code> (in multiple languages). I want to pass the Texts collection to JS to do some treatments with jQuery.</p>
  
  <pre><code>{% for tag in tags %}
      {% if tag.texts|default %}
          &lt;div data-tag-texts="{{ tag.texts|json_encode }}"&gt;...&lt;/div&gt;
      {% endif %}
  
      ...
  {% endfor %}
  </code></pre>
  
  <p>But it returns an empty object in JS : <code>Object {}</code> whereas my collection of Texts isn't empty. Usually, the Texts is an object of objects.</p>
  
  <p>I tried a lot of things but with the same result :</p>
  
  <pre><code>{{ tag.texts|json_encode }}
  {{ tag.texts|json_encode(constant('JSON_PRETTY_PRINT'))|raw }}
  </code></pre>
  
  <p>I would like to browse texts in order to show everyone in languages tabs. And all of this in a Boostrap Modal. So, I have to get the texts in javascript.</p>
  
  <p>Thanks for your help.</p>