इसके लिए, आप replace() के साथ parse() का उपयोग कर सकते हैं। कोड निम्न है:
उदाहरण
var studentDetails = `"{""name"": ""John"",""subjectName"": ""Introduction To JavaScript""}"`; console.log("The actual object="); console.log(studentDetails); var removeFirstAndLast = studentDetails.substring(1,studentDetails.length-1) var removeDoubleQuotes = removeFirstAndLast.replace(/""/gi, `"`) console.log(removeDoubleQuotes) var output = JSON.parse(removeDoubleQuotes); console.log(output);
उपरोक्त प्रोग्राम चलाने के लिए, आपको निम्न कमांड का उपयोग करना होगा:
node fileName.js.
यहां, मेरी फाइल का नाम demo103.js है।
आउटपुट
यह निम्न आउटपुट उत्पन्न करेगा:
PS C:\Users\Amit\JavaScript-code> node demo103.js The actual object= "{""name"": ""John"",""subjectName"": ""Introduction To JavaScript""}" {"name": "John","subjectName": "Introduction To JavaScript"} { name: 'John', subjectName: 'Introduction To JavaScript' }