{"action":"created","issue":{"url":"https://api.github.com/repos/js-cookie/js-cookie/issues/190","repository_url":"https://api.github.com/repos/js-cookie/js-cookie","labels_url":"https://api.github.com/repos/js-cookie/js-cookie/issues/190/labels{/name}","comments_url":"https://api.github.com/repos/js-cookie/js-cookie/issues/190/comments","events_url":"https://api.github.com/repos/js-cookie/js-cookie/issues/190/events","html_url":"https://github.com/js-cookie/js-cookie/issues/190","id":152750755,"number":190,"title":"Automatic JSON decoding","user":{"login":"CupOfTea696","id":7327050,"avatar_url":"https://avatars.githubusercontent.com/u/7327050?v=3","gravatar_id":"","url":"https://api.github.com/users/CupOfTea696","html_url":"https://github.com/CupOfTea696","followers_url":"https://api.github.com/users/CupOfTea696/followers","following_url":"https://api.github.com/users/CupOfTea696/following{/other_user}","gists_url":"https://api.github.com/users/CupOfTea696/gists{/gist_id}","starred_url":"https://api.github.com/users/CupOfTea696/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CupOfTea696/subscriptions","organizations_url":"https://api.github.com/users/CupOfTea696/orgs","repos_url":"https://api.github.com/users/CupOfTea696/repos","events_url":"https://api.github.com/users/CupOfTea696/events{/privacy}","received_events_url":"https://api.github.com/users/CupOfTea696/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/js-cookie/js-cookie/milestones/7","html_url":"https://github.com/js-cookie/js-cookie/milestones/v2.1.2","labels_url":"https://api.github.com/repos/js-cookie/js-cookie/milestones/7/labels","id":1695064,"number":7,"title":"v2.1.2","description":"","creator":{"login":"FagnerMartinsBrack","id":835857,"avatar_url":"https://avatars.githubusercontent.com/u/835857?v=3","gravatar_id":"","url":"https://api.github.com/users/FagnerMartinsBrack","html_url":"https://github.com/FagnerMartinsBrack","followers_url":"https://api.github.com/users/FagnerMartinsBrack/followers","following_url":"https://api.github.com/users/FagnerMartinsBrack/following{/other_user}","gists_url":"https://api.github.com/users/FagnerMartinsBrack/gists{/gist_id}","starred_url":"https://api.github.com/users/FagnerMartinsBrack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FagnerMartinsBrack/subscriptions","organizations_url":"https://api.github.com/users/FagnerMartinsBrack/orgs","repos_url":"https://api.github.com/users/FagnerMartinsBrack/repos","events_url":"https://api.github.com/users/FagnerMartinsBrack/events{/privacy}","received_events_url":"https://api.github.com/users/FagnerMartinsBrack/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":17,"state":"open","created_at":"2016-04-09T08:26:56Z","updated_at":"2016-05-07T08:55:16Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-05-03T11:18:22Z","updated_at":"2016-05-08T15:25:22Z","closed_at":"2016-05-07T00:58:41Z","body":"Could support for automatic JSON decoding be added? It could be done by adding a JSON map cookie that contains all cookies that were encoded to JSON. It should make sure to remove items from the JSON map if the value has changed (e.g. if you set it again but to a string)"},"comment":{"url":"https://api.github.com/repos/js-cookie/js-cookie/issues/comments/217726905","html_url":"https://github.com/js-cookie/js-cookie/issues/190#issuecomment-217726905","issue_url":"https://api.github.com/repos/js-cookie/js-cookie/issues/190","id":217726905,"user":{"login":"CupOfTea696","id":7327050,"avatar_url":"https://avatars.githubusercontent.com/u/7327050?v=3","gravatar_id":"","url":"https://api.github.com/users/CupOfTea696","html_url":"https://github.com/CupOfTea696","followers_url":"https://api.github.com/users/CupOfTea696/followers","following_url":"https://api.github.com/users/CupOfTea696/following{/other_user}","gists_url":"https://api.github.com/users/CupOfTea696/gists{/gist_id}","starred_url":"https://api.github.com/users/CupOfTea696/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CupOfTea696/subscriptions","organizations_url":"https://api.github.com/users/CupOfTea696/orgs","repos_url":"https://api.github.com/users/CupOfTea696/repos","events_url":"https://api.github.com/users/CupOfTea696/events{/privacy}","received_events_url":"https://api.github.com/users/CupOfTea696/received_events","type":"User","site_admin":false},"created_at":"2016-05-08T15:25:22Z","updated_at":"2016-05-08T15:25:22Z","body":"@FagnerMartinsBrack Yes, but I mean that the normal .get would automatically decode JSON if the original cookie was set as JSON. \r\n\r\nSimple example to illustrate:\r\n```js\r\nCookies.set('name', {prop: 'value'});\r\n\r\nvar name = Cookies.get('name');\r\nname.prop === 'value'; // true\r\n```\r\n\r\nBehind the scenes, two cookies would be set: the cookie `name` and the cookie `__json_map`. The value of the JSON map cookie would be `\"['name']\"`. When `Cookies.get` is called, the library would get the JSON map (and store it internally so we don't need to get it again as long as the page doesn't reload) and JSON parse it. Then it would check if the value `name` is in the JSON map array. If it is, it will retrieve the requested cookie and JSON parse it. If not, it will simply retrieve the cookie. \r\n\r\nThere's a few other ways this could be approached (e.g. prefixing the cookie value with an identifier string that indicates the cookie is JSON stringified) but this seems to me the best solution since a back-end could still retrieve the cookie without having to know how the front-end cookie library works."}}