I need to create a DataTable using .NET to read a Json and get the values that we pass the path in as parameter to the app, including nested values, and that DataTable need to have as many rows as values the Json has, so if the Json has an one property with an array of 3 items, then it has to insert 3 rows into the DataTable with the same values except for this property.
The input could be any Json and as many paths could be passed into the app, so everything has to be dynamic in order to handle it.
An example of a JSON input could be this:
{
"RootKey": "RootValue",
"Records": [
{
"SomeKey": "SomeValue",
"Properties": [
{
"Type": "Type 1",
"SubTypes": [
{
"SubType": "SubType 1"
},
{
"SubType": "SubType 2"
}
]
},
{
"Type": "Type 2"
},
{
"Type": "Type 3",
"SubTypes": [
{
"SubType": "SubType 3"
},
{
"SubType": "SubType 4"
},
{
"SubType": "SubType 5"
}
]
}
]
},
{
"SomeKey": "OtherValue",
"Properties": [
{
"Type": "Type 4"
},
{
"Type": "Type 5"
}
]
},
{
"SomeKey": "AndAnother",
"Properties": [
{
"Type": "Type 6"
}
]
}
]
}
and passing this in as a parameter
List<string> paths = new List<string>{"Rootkey", "Records/SomeKey", "Records/Properties/Type", "Records/Properties/Type/SubTypes/SubType"}
then will need to return a DataTable as this one:
|RootKey |SomeKey |Type |SubType |
|———–|———–|——-|———-|
|RootValue |SomeValue |Type 1 |SubType 1 |
|RootValue |SomeValue |Type 1 |SubType 2 |
|RootValue |SomeValue |Type 2 |null |
|RootValue |SomeValue |Type 3 |SubType 3 |
|RootValue |SomeValue |Type 3 |SubType 4 |
|RootValue |SomeValue |Type 3 |SubType 5 |
|RootValue |OtherValue |Type 4 |null |
|RootValue |OtherValue |Type 5 |null |
|RootValue |AndAnother |null |null |