Skip to content

Instantly share code, notes, and snippets.

@joeSaad
Last active August 29, 2015 14:13
Show Gist options
  • Save joeSaad/fde88bb3140201a6ad40 to your computer and use it in GitHub Desktop.
Save joeSaad/fde88bb3140201a6ad40 to your computer and use it in GitHub Desktop.
Create JSON object from string, string could be a cookie.
var person = "name=Joe;age=34;location=Texas;hobby=soccer";
var ca = person.split(';');
var obj = {};
for (var i= 0; i<ca.length; i++){
var loc = ca[i].indexOf('=');
var p = ca[i].slice(0, loc);
eval("obj." + p + " = '" + ca[i].slice(loc+1) + "'");
}
alert(JSON.stringify(obj));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment