Posted on

Magento 2 Plugin Around Execute Controller

Existing controller that returns a JSON.

public function execute()

$customer = $this->_customerModel->getById(175);
$resultJson = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_JSON);
‘status’ => ‘ok’,
‘message’ => ‘Success.’,
‘data’ => $customer->__toArray()

return $resultJson;


I have an afterExecute plugin where I try to get the data of the result

public function afterExecute(TestEndpoint $subject, $result)
$result2 = json_decode($result);
return $result;

There is an error saying thet $result is an Object not a JSON string. I want to get the customer data that was returned in the controller. How do I do that?

Leave a Reply

Your email address will not be published. Required fields are marked *