Deserialize json with known and unknown fields

An even easier option to tackling this problem would be to use the JsonExtensionDataAttribute from JSON .NET

public class MyClass
{
   // known field
   public decimal TaxRate { get; set; }

   // extra fields
   [JsonExtensionData]
   private IDictionary<string, JToken> _extraStuff;
}

There’s a sample of this on the project blog here

UPDATE Please note this requires JSON .NET v5 release 5 and above

Leave a Comment