Convert object into nested array using Ruby Logstash

My XML structure is

<OrderReleases>                 
    <OrderRelease ShipNode="53" />                
</OrderReleases>

After xml parsing with the below code

xml{
source => "message"
store_xml => true
target => "order"
force_array => false
}

Getting it as an object instead of list

"OrderReleases": {
            "ShipNode": "53"
  }

But I would like to have the output structure like below

 "OrderReleases": [
     {
                "ShipNode": "53"
      }
  ]

How can I achieve it using ruby?

Please advise any one.

Remove this

force_array => false

and it will be an array, as you want.

Thanks Badger for the reply. But can't use your solution as my XML is pretty huge and there are other nested arrays and objects into it for which I need force_array => false.

I am looking for some ruby code to handle this.

Would like to add one more input to the question when the above XML OrderReleases contains more than one element (OrderRelease) then the data is storing in the correct format into the Elastic but the same is not the case if it has only one element.

Tried something like this:

messageOrderRelease= []
event.get("[OrderReleases][OrderRelease]").each { |item|
messageOrderRelease << item
logger.info("item value", "value" => item)
}

Here item is coming as null. And logger.info is writing ["Shipnode": "53"]

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