How can JSON strings be parsed using the json_decode function in PHP?

To parse JSON strings using the json_decode function in PHP, you simply need to pass the JSON string as the first parameter to the function. This will return an array or object representing the JSON data. Make sure to handle any errors that may occur during the decoding process.

$json_string = '{"name": "John", "age": 30, "city": "New York"}';
$data = json_decode($json_string, true);

if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
    // Handle decoding error
    echo "Error decoding JSON: " . json_last_error_msg();
} else {
    // Access the decoded data
    echo $data['name']; // Output: John
    echo $data['age']; // Output: 30
    echo $data['city']; // Output: New York
}