I am trying to deserialize below nested Json into a custom c# type which is also described below but I keep getting the paths key as null in the deserialized object. Below is the code, any suggestions on how can this be correctly deserialized are really appreciated.
Json:
{ "swagger": "2.0", "info": { "version": "v1", "title": "API Service" }, "host": "[email protected]", "basePath": "/test", "schemes": ["https"], "paths": { "/activity/actions": { "get": { "Tags": "activity", "Description": "Test", " ": "GET/activity/actions" //Empty Key }, "put": { "Tags": "activity", "Description": "Test", " ": "PUT/activity/actions" } }, "/Test2Controller/DoAction": { "get": { "Tags": "Test2Controlle", "Description": "Test", " ": "GET/activity/actions" }, "put": { "Tags": "Test2Controlle", "Description": "Test", " ": "PUT/activity/actions" }, "POST": { "Tags": "Test2Controlle", "Description": "Test", " ": "POST/activity/actions" } } } } My C# Object
public class SwaggerJsonObject { public string Swagger { get; set; } public Info Info { get; set; } public string Host { get; set; } public string BasePath { get; set; } public string[] Schemes { get; set; } public Path Paths { get; set; } } public class Info { public string Version { get; set; } public string Title { get; set; } } public class Path { public List<Controllers> Controllers { get; set; } } public class Controllers { public List<RestVerbs> RestVerbs { get; set; } } public class RestVerbs { public string[] tags { get; set; } public string description { get; set; } public string EmptyKey { get; set; } } } Caller:
var deserializedObjedt = JsonConvert.DeserializeObject<SwaggerJsonObject>(json); Error/Issue:
Values in Paths key are null.
Pathsdoesn't match the JSON. I'd expect the JSON to look like"paths": { "controllers": [ { "restVerbs": [ "description": "abc" ] } ] }based on your C# classes. Note that we don't seecontrollersorrestVerbsin the JSON in your question.