const incomingJson = '{"name":"Asha","roles":["admin","editor"],"active":true}'; const profile = JSON.parse(incomingJson); console.log(`name: ${profile.name}`); console.log(`second role: ${profile.roles[1]}`); const outboundJson = JSON.stringify( { name: profile.name, active: profile.active, roles: profile.roles, }, null, 2, ); console.log("stringified:"); console.log(outboundJson); const roundTrip = JSON.parse(outboundJson); console.log(`round trip active: ${roundTrip.active}`); try { JSON.parse("{'name':'Asha'}"); } catch (error) { console.log(`malformed JSON: ${error.name}`); }