I need help with parsing the following

I have a script that uses curl and the $response comes back like the following:

    "balance": 1162,
    "batch_id": 123456789,
    "cost": 2,
    "num_messages": 1,
    "message": {
        "num_parts": 1,
        "sender": "Textlocal",
        "content": "This is your message"
    "messages": [
            "id": "1151346216",
            "recipient": 447123456789
    "status": "success"

How would i get it so that i could run a mysql query if the status = suscess and if it fails it echo’s back an error message?

i am struggling to understand how to parse json

You can use the json_decode() function which converts a JSON string into an stdClass, see the following example where $response equals your cURL response.

$jsonData = json_decode($response);

if ($jsonData->status === 'success') {
    // Success code
} else {
    // Failed code

Major Thank You for that!