{"id":815,"date":"2015-09-15T10:27:10","date_gmt":"2015-09-15T10:27:10","guid":{"rendered":"http:\/\/blog.silverterra.net\/?p=815"},"modified":"2015-09-15T10:27:10","modified_gmt":"2015-09-15T10:27:10","slug":"store-object-in-the-sessionstorage","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=815","title":{"rendered":"store object in the SessionStorage"},"content":{"rendered":"<blockquote><p>Goal: to store object on the client side<\/p><\/blockquote>\n<p>The following code is simple not working:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nvar obj = {id: 1, name: 'cat'};\r\nsessionStorage[&quot;pet&quot;] = obj;\r\n...\r\nconsole.log(sessionStorage[&quot;pet&quot;]);\r\n<\/pre>\n<p>the result is: <code data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">[object Object]<\/code><\/p>\n<p>We need to stringify the object before the store like this:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nvar obj = {id: 1, name: 'cat'};\r\nsessionStorage[&quot;pet&quot;] = JSON.stringify(obj);\r\n...\r\nconsole.log(JSON.parse(sessionStorage[&quot;pet&quot;]));\r\n<\/pre>\n<p>now the result is: <code data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">Object {id: 1, name: 'cat'}<\/code><\/p>\n<p>and we are happy&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: to store object on the client side The following code is simple not working: the result is: We need to stringify the object before the store like this: now the result is: and we are happy&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-815","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=815"}],"version-history":[{"count":1,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/815\/revisions"}],"predecessor-version":[{"id":816,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/815\/revisions\/816"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}