I need assistance with converting the given string into a JSON object. Here is the string:
{\"Warranty\": [ \n { \n \"Name\": \"test\", \n \"Type\": \"test2\", \n \"Months\": \"6\", \n }, \n { \n \"Name\": \"Test6\", \n \"Type\": \"test7\", \n \"Months\": \"6\", \n }, \n { \n \"Name\": \"test9\", \n \"Type\": \"test10\", \n \"Miles\": \"10000\", \n } \n ]}
Could someone assist me in converting the above string to a JSON Object?
I have attempted to use the following code, but I am still receiving a string value instead of an object:
var body = " {\"Warranty\": [ \n { \n \"Name\": \"test\", \n \"Type\": \"test2\", \n \"Months\": \"6\", \n }, \n { \n \"Name\": \"Test6\", \n \"Type\": \"test7\", \n \"Months\": \"6\", \n }, \n { \n \"Name\": \"test9\", \n \"Type\": \"test10\", \n \"Miles\": \"10000\", \n } \n ]} ".replace(/\r?\n|\r/g, "").replace(/\s+/g, "");
var json=body.replace(/['"]+/g, '');
var object = JSON.stringify(json);
object = JSON.parse(object)