framework/web/Controller.php
public function asJson($data)
    {
        $response = Yii::$app->getResponse();
        $response->format = Response::FORMAT_JSON;
        $response->data = $data;
        return $response;
    }
public function asJson($data)
    {
        $response = Yii::$app->getResponse();
        $response->format = Response::FORMAT_JSON;
        $response->data = $data;
        return $response;
    }
public function asJson ( $ data ) { $ response = Yii :: $ app -> getResponse ( ) ; $ response -> format = Response :: FORMAT_JSON ; $ response -> data = $ data ; return $ response ; }
Send data formatted as JSON.

This method is a shortcut for sending data formatted as JSON. It will return
the [[Application::getResponse()|response]] application component after configuring
the [[Response::$format|format]] and setting the [[Response::$data|data]] that should
be formatted. A common usage will be:

```php
return $this->asJson($data);
```

@param mixed $data the data that should be formatted.
@return Response a response that is configured to send `$data` formatted as JSON.
@since 2.0.11
@see Response::$format
@see Response::FORMAT_JSON
@see JsonResponseFormatter
Send data formatted as JSON .