detecting json decode failure in php using -'php,json'

detecting json decode failure in php  using -'php,json'

When using PHP's json_decode(), I don't see a way to distinguish between a NULL return value indicating a failure in decoding and a correctly decoded NULL value:

var_dump(json_decode('nonsense')); // returns NULL
var_dump(json_decode(json_encode(NULL))); // also returns NULL

And case one doesn't throw an exception. So I'm not sure how to test for a decode failure.


asked Sep 7, 2015 by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.