0

I am trying to decode the JSON in normal string and print that in the info log in Magento 2.4.0 but I am getting nothing in the info log. Adding the code below anyone please suggest a solution for this.

Code I am using

public function execute()
{
 $result = $this->resultJsonFactory->create();
 $isSuccess = $this->tracking->createApi();
 $jsonresponse = json_decode($isSuccess); // decoding here
 $this->logger->info(var_dump($jsonresponse)); // trying to print in info log
 return $result->setData(['success' => $isSuccess]);
}

$isSuccess - this variable has the below JSON data

Coveolog.INFO: {"sourceType":"PUSH","id":"dsspartnersorggrc3y48w-uk7awlmkozpufpe6pwaeoycmpy","name":"DSS-Coveo_M2-Integration-B2C-product-en_US","sourceVisibility":"SHARED","customParameters":{},"information":{"sourceStatus":{"type":"CREATING","timestamp":1617776580670,"allowedOperations":["DELETE"]},"numberOfDocuments":0,"documentsTotalSize":0},"pushEnabled":true,"onPremisesEnabled":false,"streamEnabled":false,"logicalIndex":"default","preConversionExtensions":[],"postConversionExtensions":[],"permissions":{"permissionLevels":[{"name":"Source Specified Permissions","permissionSets":[{"name":"Shared","permissions":[{"allowed":true,"identityType":"GROUP","identity":"@","securityProvider":"Email Security Provider"}]}]}]},"urlFilters":[{"filter":"*","includeFilter":true,"filterType":"WILDCARD"}],"ocrFileTypes":[],"resourceId":"dsspartnersorggrc3y48w-uk7awlmkozpufpe6pwaeoycmpy"} [] []

Diana
5,3701 gold badge12 silver badges27 bronze badges
asked Apr 7, 2021 at 6:33

1 Answer 1

0
  1. You don't need to use var_dump() when logging something in a file; the function is used when you want to dump info on the browser instead.
  2. When decoding, I would suggest you use the function like this json_decode($isSuccess, true) so that your variable's content is properly converted to associative array and not object.
answered Apr 7, 2021 at 11:48
6
  • I tried as per your comment, but I am not getting the result. Commented Apr 7, 2021 at 12:05
  • hmm ok, well i am not entirely sure how is your message formed, maybe i am missing something. Commented Apr 7, 2021 at 13:05
  • I am writing this code inside the controller is that correct as per Magento standards? Commented Apr 7, 2021 at 13:21
  • can you also try this? json_decode(trim($isSuccess), true);? Commented Apr 8, 2021 at 11:53
  • this is also not working. Commented Apr 8, 2021 at 13:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.