Skip to content

Instantly share code, notes, and snippets.

@dana-ross
Created January 30, 2016 17:33
Show Gist options
  • Save dana-ross/1cfcdb3d35f1b18f4422 to your computer and use it in GitHub Desktop.
Save dana-ross/1cfcdb3d35f1b18f4422 to your computer and use it in GitHub Desktop.
<?php
$good = json_decode('{ "label": "This is valid JSON", "value": 5 }' );
$bad = json_decode('{ "label": This is invalid JSON, "value": 5 }' );
if( is_null( $good ) ) {
echo "Couldn't parse good JSON\n";
}
else {
echo $good->value . "\n";
}
if( is_null( $bad ) ) {
echo "Couldn't parse bad JSON\n";
}
else {
echo $bad->value . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment