title: Detect bad json data in PHP json_decode()?
body: <p>I'm trying handle bad json data when parsed through json_decode(). I'm using the following script:</p>
  
  <pre><code>if(!json_decode($_POST)) {
    echo "bad json data!";
    exit;
  }
  </code></pre>
  
  <p>If $_POST equals:</p>
  
  <pre><code>'{ bar: "baz" }'
  </code></pre>
  
  <p>Then json_decode handles the error fine and spits out "bad json data!";
  However, if I set $_POST to something like "invalid data", it gives me:</p>
  
  <pre><code>Warning: json_decode() expects parameter 1 to be string, array given in C:\server\www\myserver.dev\public_html\rivrUI\public_home\index.php  on line 6
  bad json data!
  </code></pre>
  
  <p>Do I need to write a custom script to detect valid json data, or is there some other nifty way to detect this?</p>