# How can I convert a given array structure?

**URL:** https://discuss.elastic.co/t/how-can-i-convert-a-given-array-structure/168635
**Category:** Logstash
**Created:** [February 15, 2019, 6:53pm UTC](https://discuss.elastic.co/t/how-can-i-convert-a-given-array-structure/168635 "2019-02-15T18:53:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Skeeve](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@Skeeve](https://discuss.elastic.co/u/Skeeve)
#### Post date: [February 15, 2019, 6:53pm UTC](https://discuss.elastic.co/t/how-can-i-convert-a-given-array-structure/168635/1 "2019-02-15T18:53:25Z")

</div>

Hi,

I'm still in the beginning of understanding how to use logstash.

I have this structure in my event's JSON.

```
"testDetails":[
    {
        "placeholder":"NO_SECURE_FLAG_SET",
        "values":{…some more stuff…}
    },
    {
        "placeholder":"NO_HTTPONLY_FLAG_SET",
        "values":{…some more stuff…}
    },
    …maybe more placeholders…
]

```

Is there any filter which will allow me to convert this to

```
"testdetails":["NO_SECURE_FLAG_SET", "NO_HTTPONLY_FLAG_SET", …the other "placeholder" values.]
```

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [February 15, 2019, 7:57pm UTC](https://discuss.elastic.co/t/how-can-i-convert-a-given-array-structure/168635/2 "2019-02-15T19:57:57Z")

</div>

You could do that using a ruby filter

```
    ruby {
        code => '
            td = event.get("testDetails")
            if td
                a = []
                td.each { |x|
                    a << x["placeholder"]
                }
                event.set("placeholders", a)
            end
        '
    }
```

---

<div class="post-metadata">

### Author: ![Skeeve](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@Skeeve](https://discuss.elastic.co/u/Skeeve)
#### Post date: [February 15, 2019, 9:03pm UTC](https://discuss.elastic.co/t/how-can-i-convert-a-given-array-structure/168635/3 "2019-02-15T21:03:09Z")

</div>

> [@Badger](#):
>
> ruby { code =\> ' td = event.get("testDetails") if td a = td.each { |x| a \<\< x["placeholder"] } event.set("placeholders", a) end ' }

Thanks a lot @Badger it works.

---

<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: [March 15, 2019, 9:03pm UTC](https://discuss.elastic.co/t/how-can-i-convert-a-given-array-structure/168635/4 "2019-03-15T21:03:10Z")

</div>

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