# How to return json output from template file

**URL:** <https://discourse.slimframework.com/t/how-to-return-json-output-from-template-file/600>\
**Category:** Questions\
**Created:** [August 8, 2016, 7:36pm UTC](https://discourse.slimframework.com/t/how-to-return-json-output-from-template-file/600 "2016-08-08T19:36:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashickur-noor](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/ashickur-noor/32/189_2.png) [@ashickur-noor](https://discourse.slimframework.com/u/ashickur-noor)\
**Post date:** [August 8, 2016, 7:36pm UTC](https://discourse.slimframework.com/t/how-to-return-json-output-from-template-file/600/1 "2016-08-08T19:36:38Z")

</div>

I am very new to slim, and trying to develop a RESTful api for my existing php based web app. I want to return json output from a template file. How to do that? I am not getting any clue for it.

---

<div class="post-metadata">

**Author:** ![geggleto](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/geggleto/32/11_2.png) [@geggleto](https://discourse.slimframework.com/u/geggleto)\
**Post date:** [August 9, 2016, 12:24pm UTC](https://discourse.slimframework.com/t/how-to-return-json-output-from-template-file/600/2 "2016-08-09T12:24:32Z")

</div>

you wouldn’t render json from a template file.

```php
$app->get('/data', function ($request, $response, $args) {
    $yourData = [
        'x' => 1
    ];
    return $response->withJson($yourData);
});

```
