Sam Cogan
Sam Cogan

Reputation: 4334

Transforming JSON data

I have a website that pulls it's data from a JSON API. This is done using JSON.Net to translate the JSON into C# classes and that works great, and has done for months.

However, the developers of the API have released a new version of the API that changes the format of the data returned to me, and so this obviously now no longer fits into my C# classes.

What I am trying to establish is the best way to handle this. I could go and re-write my whole model, but this would mean massive changes to my whole site, so instead I am wondering if I can do some sort of transformation to get this new data format back into my current model. What I really need to know is what is the most efficient way to do this as I don't really want to slow things down too much by doing this transform.

Upvotes: 2

Views: 1045

Answers (1)

developer10214
developer10214

Reputation: 1186

If the adaption of the existing code is too expensive, you could:

  • create a new model that fits the new API
  • create a transform method to put the new model data into the existing model
  • maybe you can overload the constructor of your existing model to do the transformation

Upvotes: 2

Related Questions