-
Notifications
You must be signed in to change notification settings - Fork 0
jsonToArray
Corey Avis edited this page Sep 23, 2026
·
2 revisions
Safely converts a valid JSON string into a native associative PHP array.
jsonToArray(string $json): array
json (string) : The JSON string to decode.
(array)
: Returns the decoded associative array on success.
: Returns an empty array ([]) if the JSON string is malformed or decodes into a non-array scalar value.
📌 Avoids throwing unhandled script exceptions on decode errors or non-array values, returning a safe
[]fallback while logging a warning.
$cphp->jsonToArray('{"id":10,"user":"name","active":true}');
// Result: ['id' => 10, 'user' => 'name', 'active' => true]
$cphp->jsonToArray('{bad_json}');
// Result: [] (Logs a warning)
- Triggers a warning if there was an issue decoding the JSON.
arrayToJson | jsonToObject | jsonToSerial
Home | CoreyPHP | Conversion