Answers for "nodejs how to turn an object into json"

3

node string to json

const json = '{"result":true, "count":42}';
const obj = JSON.parse(json);
Posted by: Guest on April-08-2021
2

Javascript object convert into JSON

const person = {
    name: 'labib',
    age: 22,
    job: 'web-developer',
    frieds: ['ahsik', 'abir', 'alvi', 'hanafi'],
    childList: {
        firstChild: 'Salman',
        secondChild: 'Rafi',
        thirdChild: 'Anfi'
    }
}
const convertJson = JSON.stringify(person)
console.log(convertJson)
//Expected output:
/*
{"name":"labib","age":22,"job":"web-developer","frieds":["ahsik","abir","alvi","hanafi"],"childList":{"firstChild":"Salman","secondChild":"Rafi","thirdChild":"Anfi"}}
 */
Posted by: Guest on September-11-2021

Code answers related to "nodejs how to turn an object into json"

Code answers related to "Javascript"

Browse Popular Code Answers by Language