0

I am using a REST API from C# with Newtonsoft.Json. The responses include an extra, useless level.

The JSON looks like:

{
   'name': 'John Doe',
   'aliases': {
       'member': [
           'Lil Johnny',
           'John Boy'
       ]
   }
}

and I want to deserialize into something like:

class Person
{
    public string Name { get; set; }
    public string[] Aliases { get; set; }
}

I'm hoping there's some JsonProperty directive I can use to decorate Aliases to get the deserializer to discard "member" level of the Json but I can't find it.

Chris Nelson
  • 3,519
  • 7
  • 40
  • 51
  • 3
    There's no attribute for that, you need to use a [custom converter](https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm). For example, [Can I specify a path in an attribute to map a property in my class to a child property in my JSON?](https://stackoverflow.com/q/33088462/3744182) or [Can I serialize nested properties to my class in one operation with Json.net?](https://stackoverflow.com/q/30175911/3744182). – dbc Apr 07 '21 at 20:52
  • Excellent. Thank you, @dbc. – Chris Nelson Apr 08 '21 at 13:58

0 Answers0