Skip to content

Instantly share code, notes, and snippets.

@lenivene
Last active September 25, 2019 15:23
Show Gist options
  • Save lenivene/eff2adaa7c5c659254661c268fdce758 to your computer and use it in GitHub Desktop.
Save lenivene/eff2adaa7c5c659254661c268fdce758 to your computer and use it in GitHub Desktop.
Check STRING is JSON
<?php
/**
* Check string is JSON
*
* @param string $json JSON to check
*
* @return boolean|array
*/
function is_json( $json = null, $_return = false ){
if( ! is_string( $json ) ){
return false;
}
$_json = @ json_decode( $json, false );
$is_json = $_json != null;
if( $_return !== true )
return (bool) $is_json;
return ( $is_json ) ? $_json : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment