Remove dynamic nested field in JSON


(Mahipal Baid) #1

Hi ,

I have an input (JSON) like below:

// Sample input JSON doc

"TestCases": {
  "0": {
    "Verdict": "PASS",
    "tcId": 0,
    "NoOfFail": 0
  },
  "1": {
  }

Where number of test cases is not static and I want to remove field "NoOfFail" of each test case. I guess I cant use mutate as remove_filed requires a static filed value.
Can somebody help here.

Thanks,
Mahipal


(Mahipal Baid) #2

I have tried many stuff including Ruby filter like below

ruby {
code => "
if event.get('[doc][ExecutionData][TestCases]') != nil
event.set('[doc][ExecutionData][TestCases]',
event.get('[doc][ExecutionData][TestCases]').each_value { |url|
event.remove(url['Verdict'])
# event.get('[doc][ExecutionData][TestCases]').delete(url)
# url.delete('0')
}
);
end
"
}

But nothing works, Please help.


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.