How to format JSON output in Symfony How to format JSON output in Symfony json json

How to format JSON output in Symfony


its just missing its outer container.

try this:

return new JsonResponse( array( array(  "id"    => 288,  "title" => "Titanic",  "year"  => "1997")) );

this should output as:

[{"id":288,"title":"Titanic","year":"1997"}]


You have to include the items array into a parent one:

return new JsonResponse(array(    array(        "id" => 288,        "title" => "Titanic",        "year" => "1997",        ....    ),    array(        "id" => 288,        "title" => "Titanic",        "year" => "1997",        ....    )));


You have to put your data in another array to create an array of items. Just wrap the existing array in another array:

return new JsonResponse(array(    array(        "id" => 288,        "title" => "Titanic",        "year" => "1997",        ....    )));