diff --git a/book/controller.rst b/book/controller.rst index c768b33407d..ba2c1421033 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -778,6 +778,24 @@ There are also special classes to make certain kinds of responses easier: :class:`Symfony\\Component\\HttpFoundation\\StreamedResponse`. See :ref:`streaming-response`. +JSON helper +~~~~~~~~~~~ + +You can simplify sending JSON response with +:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::json` +helper:: + + $this->json($data, $status = 200, $headers = array(), $context = array()); + +For example if you want to send some simple array you can use it like this:: + + public function jsonAction() + { + $data = [1, 2, 3]; + + return $this->json($data); + } + .. seealso:: Now that you know the basics you can continue your research on Symfony