# Handle the xml parsed data, met an issue as ruby exception occurred: can't convert String into Integer

**URL:** <https://discuss.elastic.co/t/handle-the-xml-parsed-data-met-an-issue-as-ruby-exception-occurred-cant-convert-string-into-integer/133642>\
**Category:** Logstash\
**Created:** [May 29, 2018, 8:45am UTC](https://discuss.elastic.co/t/handle-the-xml-parsed-data-met-an-issue-as-ruby-exception-occurred-cant-convert-string-into-integer/133642 "2018-05-29T08:45:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)\
**Post date:** [May 29, 2018, 8:45am UTC](https://discuss.elastic.co/t/handle-the-xml-parsed-data-met-an-issue-as-ruby-exception-occurred-cant-convert-string-into-integer/133642/1 "2018-05-29T08:45:42Z")

</div>

Hi experts,

Here is a xml parsed data show as below:

```
"parsed" => {
        "PMSetup" => [
            [0] {
                 "startTime" => "2018-03-09T08:40:00.000+01:00",
                  "interval" => "5",
                "PMMOResult" => [
                    [0] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-amc-node-0/ContId-8ca345e0f5e4/ContType-amc"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "3"
                                ],
                                        "M2059C2" => [
                                    [0] "163580"
                                ],
                                        "M2059C1" => [
                                    [0] "4030728"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "3"
                                ]
                            }
                        ]
                    },
                    [1] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-dtd-node-0/ContId-3929221df021/ContType-dtd"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "10"
                                ],
                                        "M2059C2" => [
                                    [0] "642744"
                                ],
                                        "M2059C1" => [
                                    [0] "5648712"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "10"
                                ]
                            }
                        ]
                    },
                    [2] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-oam-node-1/ContId-07f4cdd2c44e/ContType-glsgw"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "1"
                                ],
                                        "M2059C2" => [
                                    [0] "77263"
                                ],
                                        "M2059C1" => [
                                    [0] "4117041"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "1"
                                ]
                            }
                        ]
                    },
                    [3] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-oam-node-2/ContId-1e6334140d06/ContType-glsgw"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "1"
                                ],
                                        "M2059C2" => [
                                    [0] "80325"
                                ],
                                        "M2059C1" => [
                                    [0] "4113979"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "1"
                                ]
                            }
                        ]
                    },
                 ],
        "version" => "2.3"
    }

```

I want to use ruby code to handle every PMMOResult block, the related ruby code such like this:

```
 if "_xmlparsefailure" not in [tags]{
                ruby { code => "

                                pmMeasInfo = event.get(['parsed']['PMSetup'][0]['PMMOResult'])
                                pmMeasInfo.each do |pr|

                                     ... ...

                               end
                               ... ...

                             "}

```

Then this sentence "pmMeasInfo = event.get(['parsed']['PMSetup'][0]['PMMOResult'])" make the ruby exception result.

```
[2018-05-14T19:08:18,912][ERROR][logstash.filters.ruby] Ruby exception occurred: can't convert String into Integer

```

Experts, would you please help me check this issue? How can I get every data from "PMMOResult", then put them into an array/hash\_array?

Thank you.

---

<div class="post-metadata">

**Author:** ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)\
**Post date:** [May 29, 2018, 8:54am UTC](https://discuss.elastic.co/t/handle-the-xml-parsed-data-met-an-issue-as-ruby-exception-occurred-cant-convert-string-into-integer/133642/2 "2018-05-29T08:54:27Z")

</div>

@magnusbaeck expert, can you help check it? Thank you.

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [May 29, 2018, 10:17am UTC](https://discuss.elastic.co/t/handle-the-xml-parsed-data-met-an-issue-as-ruby-exception-occurred-cant-convert-string-into-integer/133642/3 "2018-05-29T10:17:06Z")

</div>

> [@terrymu](#):
>
> `pmMeasInfo = event.get(['parsed']['PMSetup'][0]['PMMOResult'])`

For a LS nested field reference, you need to put the all the brackets in one continuous string.  
`pmMeasInfo = event.get("[parsed][PMSetup][0][PMMOResult]")`  
Single quotes are OK too - I used double quotes here as they are easier to see.

---

<div class="post-metadata">

**Author:** ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)\
**Post date:** [May 31, 2018, 10:29am UTC](https://discuss.elastic.co/t/handle-the-xml-parsed-data-met-an-issue-as-ruby-exception-occurred-cant-convert-string-into-integer/133642/4 "2018-05-31T10:29:52Z")

</div>

Guyboertje, great thanks a lot for your answer, I have modified it to  
`pmMeasInfo = event.get("[parsed][PMSetup][0][PMMOResult]")`  
Then it can work without rubyexception.

It block me a long time, thanks agian.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 28, 2018, 10:30am UTC](https://discuss.elastic.co/t/handle-the-xml-parsed-data-met-an-issue-as-ruby-exception-occurred-cant-convert-string-into-integer/133642/5 "2018-06-28T10:30:16Z")

</div>

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