0

I have some JSON that whose structure is known at compile time but at runtime some properties are not known and their name is repeated in the JSON.

What is the best approach to parse this with C# class files? At runtime I will know what the names of the properties will be and so have looked at some solutions using Dictionaries for example but cannot get the entire file to parse.

An example of the JSON is below. The values NotKnown1 and NotKnown2 are the value known at run time. Everything else is known, so I can see how to map the data below these nodes to a class. But not have the ability to map the unknown values

{
  "title": "Test Title",
  "properties": {
    "NotKnown1": {
      "type": "string",
      "default": ""
    }
      },
  "dependencies": {
    "NotKnown1": {
      "oneOf": [
        {
          "properties": {
            "NotKnown1": {
              "enum": [
                "No"
              ]
            }
          }
        },
        {
          "properties": {
            "NotKnown1": {
              "enum": [
                "Yes"
              ]
            },
            "NotKnown2": {
              "type": "string",
              "default": ""
            }
          },
          "required": [
            "NotKnown2"
          ]
        }
      ]
    }
  }
}  
DevOverflow
  • 491
  • 1
  • 5
  • 16
  • Does this answer your question? [Deserialize json with known and unknown fields](https://stackoverflow.com/questions/15253875/deserialize-json-with-known-and-unknown-fields) – Eugene Podskal Nov 29 '19 at 18:59
  • Thanks, I am just looking at the post regarding a custom jsonconverter. Will report back. – DevOverflow Nov 29 '19 at 23:01

0 Answers0