Greetings,
Question
How-to - Filter json output and get one value.
What would be the best and quick way to accomplish that.
For example, if I have the following json output
[
{
"data": "{"public_ip":"172.83.47.196","region":"Ontario","country":"Canada","city":"Toronto","location":"43.7001,-79.4163","organization":"AS46562 Performive LLC","postal_code":"M5A","timezone":"America/Toronto"} "
}
]
and I want to get the public_ip output only
172.83.47.196
Example:
Example that is working with javascript when running in browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Convert JSON String to JavaScript Object and Access Individual Values</title>
</head>
<body>
<script>
// Store JSON data in a JS variable
var json ='{"public_ip":"172.83.47.196","region":"Ontario","country":"Canada","city":"Toronto","location":"43.7001,-79.4163","organization":"AS46562 Performive LLC","postal_code":"M5A","timezone":"America/Toronto"}';
// Converting JSON-encoded string to JS object
var obj = JSON.parse(json);
// Accessing individual value from JS object
document.write(obj.public_ip + "<br>"); // Prints: 172.83.47.196
document.write(obj.region + "<br>"); // Prints: Ontario
document.write(obj.country); // Prints: Canada
</script>
</body>
</html>