js get json value code example
Example 1: change js to json
var obj = {name: "Martin", age: 30, country: "United States"};
var json = JSON.stringify(obj);
console.log(json);
"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
Example 2: key value json javascript
var jsonArray = '{"required":1, "minlength":2}'
var jsonParsedArray = JSON.parse(jsonArray);
for (key in jsonParsedArray) {
if (jsonParsedArray.hasOwnProperty(key)) {
console.log("%c "+key + " = " + jsonParsedArray[key],"color:cyan");
}
}
Example 3: json object
var myObj, x;
myObj = {"name":"John", "age":30, "car":null};
x = myObj.name;
document.getElementById("demo").innerHTML = x;
Example 4: javascript find json value
function getCountryByCode(code) {
return data.filter(
function(data){ return data.code == code }
);
}
var found = getCountryByCode('DZ');