Answers for "php check if json or string"

PHP
2

php check if json

function isJson($string) {
 json_decode($string);
 return (json_last_error() == JSON_ERROR_NONE);
}
Posted by: Guest on April-09-2020
1

php if is json object

//Simple
if (is_object(json_decode($var))) { 
  ....
}

//Else
var $x = json_decode($var);
var $y = is_object($x)?$x:....;

//Better
function json_validate($string) {
    // decode the JSON data
    $result = json_decode($string);

    // switch and check possible JSON errors
    switch (json_last_error()) {
        case JSON_ER
Posted by: Guest on March-30-2020

Code answers related to "php check if json or string"

Browse Popular Code Answers by Language