title: How to keep json_encode() from dropping strings with invalid characters
body: <p>Is there a way to keep <code>json_encode()</code> from returning <code>null</code> for a string that contains an invalid (non-UTF-8) character?</p>
  
  <p>It can be a pain in the ass to debug in a complex system. It would be much more fitting to actually see the invalid character, or at least have it omitted. As it stands, <code>json_encode()</code> will silently drop the entire string.</p>
  
  <p>Example (in UTF-8):</p>
  
  <pre><code>$string = 
    array(utf8_decode("Düsseldorf"), // Deliberately produce broken string
          "Washington",
          "Nairobi"); 
  
  print_r(json_encode($string));
  </code></pre>
  
  <p>Results in</p>
  
  <pre><code>[null,"Washington","Nairobi"]
  </code></pre>
  
  <p>Desired result:</p>
  
  <pre><code>["D�sseldorf","Washington","Nairobi"]
  </code></pre>
  
  <p><strong>Note</strong>: I am <strong>not</strong> looking to make broken strings work in json_encode(). I am looking for ways to make it easier to diagnose encoding errors. A <code>null</code> string isn't helpful for that.</p>