I want to log the values of a resultJsonFactory object in php with in Magento 2: How do I get the values I set in the $response object ?

$response = $this->resultJsonFactory->create();
$response->setData(['message' => 'bla bla bla']);

//something like that but it dosn't work
$myMessage = $response->getData('message');


I understand thant the getData is not set in the resultJsonFactory class but I can't find a way to get the values from the object.

What i am trying to get is the json string and the httpResponseCode.

enter image description here

1 Answer 1


I don't think you can retrieve it.
$this->resultJsonFactory->create(); will return an instance of the class Magento\Framework\Controller\Result\Json.
the setData() method looks like this:

public function setData($data, $cycleCheck = false, $options = [])
    $this->json = \Zend_Json::encode($data, $cycleCheck, $options);
    return $this;

This means that the data you set is json encoded and there is no getData method on it.

  • Thanks Marius but must be a way to get the value in js i just jqXHR.responseJSON.message but have to be a way to do that in php Nov 1, 2017 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.