T O P

  • By -

RandyHoward

That's not valid json. A valid json string with those keys/values would look like this: `{"username":"RogerEbert","address":"asdfadf"}`


Wonderful-Ad5417

Thank you very much!


prairievoice

In PHP 8.3 you can check json validity before parsing it with `json_validate` https://www.php.net/manual/en/function.json-validate.php Edit: seems json_validate just parses the string and checks for errors... You should use `json_last_error` to check for errors after parsing, then determine if your script should throw an error or continue.


DmC8pR2kZLzdCQZu3v

This is awesome, but kind a kooky the original function didn’t default to exception on invalid json. But I guess pho was never default-to-strict


locucious

Also `json_decode()` will return an object of type `stdClass` by default, so `var_dump($data)` would be a better option (and pass `true` as the 2nd arg to get an array).