1

How to decode a JSON data in Twig this is my code in my controller

public function testoutput($id) {
$form = $this->getDoctrine()
->getRepository(ApplicationForm::class)
->findAll();

return $this->render('testoutput.html.twig', array('form' => $form));}

My database looks like this.

id |             jsonData             | dateSigned
===|================================= |============
1  | {"fname":"Jan", "lname": "Jake"} | 10-09-2019 
===|==================================|===========
2  | {"fname":"Mike", "lname": "Ham"} | 10-10-2019 
===|==================================|===========

I want to display this data on my Twig View but I am getting this error

Unknown "json_decode" filter. Did you mean "json_encode"?

I research about this error but it seems the results and codes are already outdated still using Symfony 2 about 6 years ago. The folders and structures are already new in Symfony 4.3. Is there any new way to solve.

{% for data in form %}
{% set a = data.data_json | json_decode() %}

{% for json is a %}
    {{ json['fname'] }}
{% endfor %}

{% endfor %}
JBA
  • 219
  • 4
  • 15

0 Answers0