JS

CONVERT STRING TO OBJECT IN JAVASCRIPT

JSON ENCODED STRING var str = '{"Name":"Jon","Email":"jon@doe.com"}';    PARSE JSON  var obj = JSON.parse(thestring);

JSON DECODE

01

CSV STRING  var str = "Name,Jon,Email,jon@doe.com";   MANUAL PROCESS AND LOOP var temp = thestring.split(","); var obj = {}; for (let i=0; i<temp.length; i+=2) {   obj[temp[i]] = temp[(i+1)]; }

MANUAL CONVERT

02

var obj = {    PROPERTIES    Name: null, Email: null,    IMPORT FROM JSON STRING   inJSON : function (str) {     let temp = JSON.parse(str);     this.Name = temp.Name;     this.Email = temp.Email;   } };

"IMPORT" FUNCTION

03

PROCESS "IMPORT" var data = '{"Name":"Jon","Email":"jon@doe.com"}'; obj.inJSON(data);