How to check missing key in JSON

Hi All,

I have a dynamic JSON . I want to check if any key is missing or not.

  • “incomeexpenses”:{
    • “data”:[
      1. {
      • “basicsalary”:{},
      • “pensionincome”:{},
      • “invcesmentincome”:{},
      • “othertaxableincome”:{
        • “1”:{},
        • “2”:{}},
      • “socialsecuritybenefit”:{
        • “1”:{}},
      • “bonus”:“400”,
      • “total”:“13000”,
      • “next12month”:“Yes”,
      • “nontaxableincome”:{}}],
    • “concession_card”:“1”,
    • “current_saving_expenditure”:“Yes”,
    • “current_saving_expenditure_details”:“Business grow”,
    • “totalFinancialdetails”:“1”,
    • “estimate_total_annual_expenses1”:“500”
      }

Here I want to check “estimate_total_annual_expenses1” key is exist or not.

For parsing I am using

IncomeExpenses(“incomeexpenses”).SelectToken(“estimate_total_annual_expenses”).ToString

Where IncomeExpenses is JSON object.

Regards
AN

One of a few options and also depending on structures we can check with containskey method:

myJObject("incomeexpenses").value(of JObject).ContainsKey("estimate_total_annual_expenses1")

Other options do have the strategy

  • of retrieval and null check
  • retrieval and count check

grafik