using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
""CarName"": ""Car polish"",
""CustName"": ""Mr. Clouseau""
""SomeAddr"": ""Hightstreet 13""
Client client = JsonConvert.DeserializeObject<Client>(json, new CustomConverter());
foreach (Product product in client.ProductList)
Console.WriteLine(product.Name);
Console.WriteLine(product.IsPrivate);
Console.WriteLine(client.Name);
Console.WriteLine(client.AddressLine1);
public Client(string name, string addressLine1, List<Product> productList)
AddressLine1 = addressLine1;
ProductList = productList;
public List<Product> ProductList { get; set; }
public string Name { get; set; }
public string AddressLine1 { get; set; }
public Product(string name, bool isPrivate)
public string Name { get; set; }
public bool IsPrivate { get; set; }
class CustomConverter : JsonConverter
public override bool CanConvert(Type objectType)
return objectType == typeof(Client);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
JObject obj = JObject.Load(reader);
string name = (string)obj.SelectToken("Result.Client.MyName.CustName");
string addressLine1 = (string)obj.SelectToken("Result.Client.AddressLine1.SomeAddr");
List<Product> productList = obj.SelectToken("Result.Client.ProductList.Product")
string prodName = (string)jt.SelectToken("MyName.CarName");
bool isPublic = string.Equals((string)jt.SelectToken("MyName.IsPublic"), "True", StringComparison.OrdinalIgnoreCase);
return new Product(prodName, !isPublic);
Client client = new Client(name, addressLine1, productList);
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
throw new NotImplementedException();