5

An example would be that I am consuming json from an api. The api is not consistent in how it returns the json. Say you have an Author and it has a property of Books[]. The api is unfortunately choosing to return Author.Books (of type Book) in cases when there is only one book. The prefered method would be to return just one Book inside Author.Books[].

Json.NET understandably throws a serialization exception when I try to have it deserialize a chunk of json and it finds "Author":{"Book":{... mixed in with "Author":{"Book":["...

Is there a way around this?

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Roger
  • 2,063
  • 4
  • 32
  • 65

2 Answers2

7

Does this answer your question?

Deserializing JSON when sometimes array and sometimes object

Community
  • 1
  • 1
James Newton-King
  • 48,174
  • 24
  • 109
  • 130
0

I guess the best would be fix the json through a regex replace before sending to the deserializer. If you put here a full sample of a json provided by the API, and a json accepted, i could make the regex for you.

ariel
  • 15,620
  • 12
  • 61
  • 73