{"id":794,"date":"2020-02-09T03:39:30","date_gmt":"2020-02-09T03:39:30","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/02\/09\/get-serialize-value-in-array-format-magento-2\/"},"modified":"2025-05-22T15:00:19","modified_gmt":"2025-05-22T09:30:19","slug":"get-serialize-value-in-array-format-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-serialize-value-in-array-format-magento-2\/","title":{"rendered":"The Secret to Get Serialize Value in Array Format in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/developer.adobe.com\/commerce\/docs\/\" target=\"_blank\" rel=\"noreferrer noopener\">Serialization<\/a> in Magento 2 allows converting data into a string using serialize() method to store in a database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reverse process is unserialization using the <strong>unserialize()<\/strong>&nbsp;method of the native Magento interface.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This method is used to <strong>get serialize value in array format in Magento 2<\/strong>.s<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Earlier I posted the solution to <a href=\"https:\/\/meetanshi.com\/blog\/magento-2-convert-array-data-into-serialize-format\/\" target=\"_blank\" rel=\"noreferrer noopener\">convert array data into serialize format in Magento 2<\/a>. The below code does exactly the opposite of what the serialize() method does.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The unserialize() method converts a serialized string back into a string, integer, float, boolean, or array data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Serialize Value In Array Format In Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use Magento\\Framework\\Serialize\\SerializerInterface;\n\nprivate $serializer;\n\npublic function __construct(SerializerInterface $serializer) {\n  $this->serializer = $serializer;\n}\n\n\/\/you need to pass serialize value as a parameter in this function\npublic function getSerializeData($arr)\n{\n    $unSerializeData = $this->serializer->serialize($arr);\n    return $unSerializeData;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s all for Magento 2 unserialization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please share the solution via social media with fellow developers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Serialization in Magento 2 allows converting data into a string using serialize() method to store in a database. The reverse process is unserialization using the&#8230;<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-794","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=794"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions"}],"predecessor-version":[{"id":15092,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions\/15092"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}