# Response in middleware don't have withJson method

**URL:** <https://discourse.slimframework.com/t/response-in-middleware-dont-have-withjson-method/3381>\
**Category:** Questions\
**Created:** [August 23, 2019, 9:35am UTC](https://discourse.slimframework.com/t/response-in-middleware-dont-have-withjson-method/3381 "2019-08-23T09:35:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aghezzi](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@aghezzi](https://discourse.slimframework.com/u/aghezzi)\
**Post date:** [August 23, 2019, 9:35am UTC](https://discourse.slimframework.com/t/response-in-middleware-dont-have-withjson-method/3381/1 "2019-08-23T09:35:52Z")

</div>

How can set response to json in middleware  
as I do in closure with  
return $response-\>withJson([‘one’=\>1,‘two’=\>2]);

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [August 23, 2019, 10:01am UTC](https://discourse.slimframework.com/t/response-in-middleware-dont-have-withjson-method/3381/2 "2019-08-23T10:01:21Z")

</div>

> [@aghezzi](#):
>
> withJson

The withJson method has been gone in Slim 4, because it’s not part of the PSR-7 http interface.

Instead you have a lot of other possibilities:

1. Create the json response manually

```php
$response->getBody()->write((string)json_encode(['one' => 1, 'two' => 2]));

$response = $response->withHeader('Content-Type', 'application/json');

return $response;

```

If you need this very often, I would recommend using a [JsonRenderer](https://github.com/odan/slim4-skeleton/blob/master/src/Renderer/JsonRenderer.php). [Example Action](https://github.com/odan/slim4-skeleton/blob/master/src/Action/Customer/CustomerFinderAction.php#L31)
