1

I am having a json text file as :

[
    { 
        "productId":"17213812",
        "returnPolicies": {
            "user":"Regular Guest"
        }
    },
    {
        "productId":"17813832",
        "returnPolicies":[]
    }
] 

and I am getting error for returnPolicies since it has different properties. But I want only returnpoliciesuser so If i use e.returnpolicies.user it is showing error for second array.. Anyone knows how to skip "returnPolicies":[] and search only e.returnpolicies.user("returnPolicies":{"user":"Regular Guest"}) ?

Markus
  • 20,838
  • 4
  • 31
  • 55

1 Answers1

0

This is how you can do it.

using (var jr = new ChoJSONReader("sample6.json")
    .WithField("ProductId", jsonPath: "$.productId")
    .WithField("User", jsonPath: "$.returnPolicies.user")
    )
{
    foreach (var item in jr)
        Console.WriteLine(item.ProductId + " " + item.User);
}
Cinchoo
  • 6,088
  • 2
  • 19
  • 34