Existing controller that returns a JSON.
public function execute()
{
$customer = $this->_customerModel->getById(175);
$resultJson = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON);
$resultJson->setData(
[
'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?