Returning nested data via json

Topics: Web Api
Jun 13, 2011 at 8:33 AM

Hi

What I'm trying to do may be against RESTful principals so please let me know if it is...

I have a resource called contact. the Contact has an address. In my implementation of the Contact resource I have a Contact class which has an embedded Address class, for example:

public class AddressDetails
{
  public string Line1 {get;set;}
  public string Line2 {get;set;}
  public string Line3 {get;set;}
}

public class Contact
{
  public string Name {get;set;}
  public AddressDetails Address {get;set;}
}

 

Now when I query my resource via http://myservice/Contacts/{id} the xml return contains the AddressDetails data as a nested type within the Contact. This is what I expected, but when querying this using json I'm not sure how I can reference the address data.

More to the point, I'm not sure if I should be returning nested classes/resources like this. Should I be returning a flattened structure?

Thanks for your help.

Graham