You can do this with the Newtonsoft.Json package, no doubt with any other json handling library too.
private void ParseJson (JToken token)
{
foreach (var prop in token.Children())
{
if (prop.Type == JTokenType.Property)
{
var p = prop as JProperty;
bool isNested = IsNested(p);
Console.WriteLine(p.Name + " " + isNested.ToString());
}
}
}
private bool IsNested(JProperty token)
{
bool isNested = false;
if (token.Value.Type == JTokenType.Object)
{
isNested = true;
}
else if (token.Value.Type == JTokenType.Array)
{
isNested = true;
}
return isNested;
}
usage;
var tokens = new List<JToken>();
string json = "[{one:\"apples\", two:\"oranges\", children:[{three:\"bananas\"}]}]";
dynamic jResult = JsonConvert.DeserializeObject(json);
var token = jResult as JToken;
if (token.Type == JTokenType.Array)
{
tokens.AddRange(token.Children());
}
else
{
tokens.Add(token);
}
foreach (var item in tokens)
{
ParseJson(item);
}
That's a starting point anyway, it will probably need more work to make it more robust and to handle a greater variety of json, it depends how variable your json in.