title: Deserialize only valid objects by ignoring errors
body: <p>Is there a built-in way (or a trick) for parsing only <em>valid</em> objects and ignoring <em>invalid</em> ones?</p>
  
  <hr>
  
  <p><strong>Not a duplicate</strong></p>
  
  <p>The question <a href="https://stackoverflow.com/questions/29797965/ignoring-an-invalid-field-when-deserializing-json-in-json-net">Ignoring an invalid field when deserializing json in Json.Net
  </a> does not answer my question because it's about a custom serializer for a very specific field of date-time type. I'm seeking a generic solution working for any property and any object. </p>
  
  <p>In other words if anything is invalid, just ignore it and contintue to the next entry. As far as json is concerned, the file is correct but the content might not match the expected types in some places. It can by anything.</p>
  
  <hr>
  
  <p>Background: The file contains an array of many <em>workflows</em> and a single <em>damaged</em> entry should not break the entire configuration and virtually disable them all.</p>
  
  <hr>
  
  <p>Here's an example demonstrating what I mean. Let's say I have an array of <code>User</code>s but one entry instead of using a <code>string</code> for the <code>Name</code> uses an array (it might by any combination of invalid values, like an object where an array is expected.</p>
  
  <p>I'd like to deserialize this array and ignore entries that couldn't be deserialized. This means that the expected result should be two users, <em>John</em> &amp; <em>Tom</em>.</p>
  
  <p>I tried to use the <code>Error</code> handler but it does not work this way. It doesn't allow me to skip the errors.</p>
  
  <pre><code>void Main()
  {
      var json = @"
      [
          {
              'Name': 'John',
          },
          {
              'Name': [ 'John' ]
          },
          {
              'Name': 'Tom',
          },
      ]   
      ";
  
      var users = JsonConvert.DeserializeObject&lt;IEnumerable&lt;User&gt;&gt;(json, new JsonSerializerSettings
      {
          Error = (sender, e) =&gt;
          {
              e.Dump();
              e.ErrorContext.Handled = true;
              e.CurrentObject.Dump();
          }
      }).Dump();
  }
  
  class User
  {
      public string Name { get; set; }
  }
  </code></pre>