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"} [] []
1 Answer 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.
- 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.
- 
 I tried as per your comment, but I am not getting the result.Ajmalriyaz– Ajmalriyaz2021年04月07日 12:05:20 +00:00Commented Apr 7, 2021 at 12:05
- 
 hmm ok, well i am not entirely sure how is your message formed, maybe i am missing something.Diana– Diana2021年04月07日 13:05:08 +00:00Commented Apr 7, 2021 at 13:05
- 
 I am writing this code inside the controller is that correct as per Magento standards?Ajmalriyaz– Ajmalriyaz2021年04月07日 13:21:31 +00:00Commented Apr 7, 2021 at 13:21
- 
 can you also try this?json_decode(trim($isSuccess), true);?Diana– Diana2021年04月08日 11:53:03 +00:00Commented Apr 8, 2021 at 11:53
- 
 this is also not working.Ajmalriyaz– Ajmalriyaz2021年04月08日 13:38:14 +00:00Commented Apr 8, 2021 at 13:38