Craft 3 Plugin Controller - returnJson() replacement? In Craft2, when making an ajax request to a plugin controller action, you would use the returnJson() method which is part of the BaseController class - which your plugin controllers extend.

This sets some headers, echo's the response and kills any further processing.

public function actionDoStuff() {

    $response = (object)[
        "message" =&gt; "Look at me! I'm JSON!"
    ];

    $this-&gt;returnJson($response);
}


In Craft 3/Yii 2 I'm having trouble finding the equivalent.
I wasn't rtfm'ing hard enough. In the docs for \yii\web\Controller, which is what the \craft\web\Controller class extends (which is what your plugin controllers extend) there is a method asJson().

return $this-&gt;asJson($response);