0

following JSONs.

Fix parts and a one that will be change for various JSONs.

{
  "prop1" : "val1",
  "prop2" : 5,
  "fixStructure1" : {
    "field1" : "value1",
    "field2" : "value2",
    "field3" : "value3"
  },
  "fixStructure2" : {
    "field4" : "value4",
    "field5" : "value5"
  },
  "dynamicStructure" : {
    "dynamicField1" : "value6",
    "dynamicField2" : "value7"
  }
}

sample 2

{
  "prop1" : "val2",
  "prop2" : 10,
  "fixStructure1" : {
    "field1" : "value1",
    "field2" : "value2",
    "field3" : "value3"
  },
  "fixStructure2" : {
    "field4" : "value4",
    "field5" : "value5"
  },
  "dynamicStructure" : {
    "dynamicField1" : "value8",
    "dynamicField3" : "value9"
  }
}

sample 3

{
  "prop1" : "val3",
  "prop2" : 1,
  "fixStructure1" : {
    "field1" : "value1",
    "field2" : "value2",
    "field3" : "value3"
  },
  "fixStructure2" : {
    "field4" : "value4",
    "field5" : "value5"
  },
  "dynamicStructure" : {
    "dynamicField3" : "value10",
    "dynamicField4" : "value11"
  }
}

What is the best way to structure the classes and deserialize each JSON to the specific object?

3
  • You can use Dictionary<string, ...> for the JSON object with dynamic property names - see the suggested duplicate. Commented Jun 29, 2024 at 23:10
  • Thanks for that. I guess it will help me in another case. I extended now these samples. The full structure also contains key-value-pairs with atomic values. And I don't think that the linked solution will help me for that (at least I don't see at the moment how). I reduced the samples because the dynamic sub structure is my problem at the moment. So the extension for clarification I hope. Commented Jun 29, 2024 at 23:21
  • What do you mean by "atomic" values? The show JSON structures should be easily converted to a class which will have Dictionary<string, string> for the dynamicStructure property. Commented Jun 29, 2024 at 23:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.