JAVASCRIPT
change js to json
var obj = {name: "Martin", age: 30, country: "United States"};
// Converting JS object to JSON string
var json = JSON.stringify(obj);
console.log(json);
// Prints: {"name":"Martin","age":30,"country":"United States"}
"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
Converting JSON to JavaScript Object
// json object
const jsonData = '{ "name": "John", "age": 22 }';
// converting to JavaScript object
const obj = JSON.parse(jsonData);
// accessing the data
console.log(obj.name); // John
change js to json
var obj = {name: "Martin", age: 30, country: "United States"};
// Converting JS object to JSON string
var json = JSON.stringify(obj);
console.log(json);
// Prints: {"name":"Martin","age":30,"country":"United States"}
"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
Converting JavaScript Object to JSON
// JavaScript object
const jsonData = { "name": "John", "age": 22 };
// converting to JSON
const obj = JSON.stringify(jsonData);
// accessing the data
console.log(obj); // "{"name":"John","age":22}"
Converting JSON to JavaScript Object
// json object
const jsonData = '{ "name": "John", "age": 22 }';
// converting to JavaScript object
const obj = JSON.parse(jsonData);
// accessing the data
console.log(obj.name); // John
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"}}
*/
Converting JavaScript Object to JSON
// JavaScript object
const jsonData = { "name": "John", "age": 22 };
// converting to JSON
const obj = JSON.stringify(jsonData);
// accessing the data
console.log(obj); // "{"name":"John","age":22}"
how to convert json to javascript object
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"}}
*/
how to convert json to javascript object