Ruby filter to extract JSON value

I have an array and need to extract the latest date value, the array below looks like this

{
    "conversations": [
        {
            "userMessages": [
                {
                    "sbdh": {
                        "documentIdentification": {
                            "creationDate": "2020-02-17T12:04:31.388Z"
                        }
                    }
                }
            ]
        },
        {
            "userMessages": [
                {
                    "sbdh": {
                        "documentIdentification": {
                            "creationDate": "2020-02-18T12:04:31.388Z"
                        }
                    }
                }
            ]
        }
    ]
}

My ruby filter

ruby {
    code => "
        arr = event.get('[conversations]')[-1];
        event.set('document_date', arr[0].sbdh.documentIdentification.creationDate);           
    "
  }

return nil class error?

Ruby exception occurred: undefined method sbdh' for nil:NilClass`

ruby {
    code => "
        dt = event.get('[conversations][-1][userMessages][0][sbdh][documentIdentification][creationDate]');            
        event.set('document_date', dt);           
    "
  }

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