Show PrettyPrint JSON in Slim3

0

I am creating a restful api with the framework Slim3 the data is returned to me with json, but to debug I like more to show the answer with a nicer format.

in% pure co_de I do it using

json_encode($datos, JSON_PRETTY_PRINT);

I have the following

$app->get('/ads', function ($request, $response, $args) {
    $db = $this->get('db');
    $datos = $db->get('ads');
    return $this->response->withJson($datos);
});
    
asked by Webserveis 05.04.2017 в 12:22
source

1 answer

1

The withJson method of the class Slim \ Http \ Response accepts 3 parameters:

  • The data you want to encode
  • The header you want to answer with
  • The options pass to the json_encode function.
  • Because of the above, the following combination

    return $this->response->withJson($datos, null, JSON_PRETTY_PRINT);
    

    Would lead to execute

    json_encode($datos, JSON_PRETTY_PRINT);
    

    Inside the method

        
    answered by 06.04.2017 / 16:39
    source