0

I have some JSON that I want to deserialize using Json.Net but I don't want to mimic the JSON object structure. For example I have this order object:

{
    "order":
    {
        "order_id": "111-22222222-33",
        "account_identifier": "my account id",
        "customer": "my customer",
        "sku": "WALM-E-500-STD",
        "amount": 500,
        "reward_message": "my message is awesome",
        "reward_subject": "my subject is awesome",
        "reward_from": "me",
        "delivered_at": "2013-11-10T12:49:00+00:00",
        "recipient": {
          "name": "me",
          "email": "my@email.com"
        },
        "reward": {
          "token": "1234567890.1234567890",
          "number": "A1234567890",
          "redemption_url": "http://some.domain.com/r/1234567890"
        }
    }
}

I don't want recipient or reward properties, instead I want to flatten those so that name, email, token, number, and redemption_url become properties of the order. Is that possible?

Rush Frisby
  • 11,388
  • 19
  • 63
  • 83

1 Answers1

1

Try this other answer on Stackoverflow: How to Convert JSON object to Custom C# object?

It shows a way to instantiate an object's properties using JSON.NET in the constructor. By doing this, you can individually map the data from your structure to the appropriate property in your object.

Community
  • 1
  • 1
Jay S
  • 7,904
  • 2
  • 39
  • 52