How to echo one value from JSON response from the code below [duplicate]

The following piece of code displays data from an API.
How do i echo only one value from the displayed data, For example only echo FIRSTNAME
I have tried many solutions from Stackoverflow and other websites but non of them works for me!

Here is the code:

<?php


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://example.com/data/XXX');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Length: 0';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

var_dump($result);

?>

Output:

string(531)"{"obj":{"result":{"FIRSTNAME":"JOHN","SECONDNAME":"DOE"}}"