Search code examples
c#jsonserializationjson.netpartial

Partially deserialize with JSON.NET, keeping some fields raw


I have a document like this

{
    "Field1": 1,
    "Field2": 2,
    "Field3": {
        Type: "TheMotherLoad"
    }
}

Which i want to convert into this class, but keeping field 3 "raw/as-is".

public class Fields {
    public int Field1 { get; set; }
    public int Field2 { get; set; }
    public string Field3 { get; set; }
}

The result should be

Field1 = 1, 
Field2 = 2, 
Field3 = "{ Type: "TheMotherLoad" }"

Possible with Json.NET?


Solution

  • Field3 could be a JObject. When you need JSON just call Field3.ToString()