How to check if particular field exists in JSON array using groovy

Viewed 28

I need to check if the particular value exists in json, if not assign default value, below is the input json array for reference:

input:

[

{
"Name": "1",
"Reports": [{
  "Report_Name": "Workday"
}]
},
{
"Name": "2",
"Fields": [
  {
     "Field_Name": "Benefits"
  }
]
}  ,

{
"Name": "3",
"Integration": [
  {
     "Field_Name": "test"
  }
]
}

]

Expected output:

  [
  {
  "Name": "1",
 "Value":"Reports_Exists" 
  },{
 "Name": "2",
 "Value":"Fields_Exists" 
  },
  {
 "Name": "3",
 "Value":"Integration_Exists" 
 }

 ]

in the above output need to configure defaults value as shown

0 Answers
Related