Get Serialize value into an array format by using an unserialize() method of native Magento interface.
unserialize() method is used to convert the array form of data in Magento 2.
This method is exactly opposite to serialize() format. For Users Readability, Convert JSON string to the array format will be helpful in any scenario.
Use the Magento\Framework\Serialize\SerializerInterface interface to retrieve unserialize data using Magento 2.
<?php namespace Jesadiya\Serialization\Model; use Magento\Framework\Serialize\SerializerInterface; class DataUnSerialize { /** * @var SerializerInterface */ private $serializer; /** * @param SerializerInterface $serializer */ public function __construct( SerializerInterface $serializer ) { $this->serializer = $serializer; } /** * get Serialize Data * * @return array */ public function getSerializeData() { $data = {"code1":"value1"}; //serialize string $additionalData = $this->serializer->unserialize($data); return $additionalData; } }
Using unserialize() objects original type would be the same, type of data wouldn’t be changed in serialize format.
echo $this->getSerializeData();
Check the link for Convert Data into serialize format
Output of serialized data:
[“code1” => “value1”]