var objJson1 = JSON.parse(JSON.stringify(objNotJson1));
const json = '{"result":true, "count":42}';
const obj = JSON.parse(json);
console.log(obj.count);
// expected output: 42
console.log(obj.result);
// expected output: true
var obj = ...;
var json = JSON.stringify(obj);
var obj2 = JSON.parse(json);
// if u have json response u can parse your json like below
getData().then(result => {
var jsonResult = JSON.stringify(result)
var parsedObject = JSON.parse(jsonResult)
parsedObject.forEach(r => {
console.log(r)
})
var str = '[{"UserName":"xxx","Rolename":"yyy"}]'; // your response in a string
var parsed = JSON.parse(str); // an *array* that contains the user
var user = parsed[0]; // a simple user
console.log(user.UserName); // you'll get xxx
console.log(user.Rolename); // you'll get yyy
const obj = JSON.parse('{"key1":"val1", "key2":0.0, "key3":"00:00"}');
console.log(obj)
console.log(obj.key1)
console.log(obj.key2)
//JSON.parse()
const json = "{"name": "Example", "age": 50}";
let parsed_json = JSON.parse(json);
console.log(`Name: ${parsed_json.name}; Age: ${parsed_json.age}`)
// Returns "Name: Example; Age: 50"
var dataResult = JSON.parse(dataResult);
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
JSON.parse(data)
const parseJSON = (json) => {
return new Function('return ' + json)();
};