# Transforming array of objects

**URL:** https://discuss.elastic.co/t/transforming-array-of-objects/234366
**Category:** Logstash
**Created:** [May 26, 2020, 3:07pm UTC](https://discuss.elastic.co/t/transforming-array-of-objects/234366 "2020-05-26T15:07:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AlessandroKP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alessandrokp/32/45312_2.png) [@AlessandroKP](https://discuss.elastic.co/u/AlessandroKP)
#### Post date: [May 26, 2020, 3:07pm UTC](https://discuss.elastic.co/t/transforming-array-of-objects/234366/1 "2020-05-26T15:07:27Z")

</div>

Hi all,

we are trying to process an event with Logstash that is generated by http\_poller input.  
The event has the following structure:

```auto
{
	"data": [
		{
			"name": "key1",
			"value": "A"
		},
		{
			"name": "key2",
			"value": "B"
		},
		{
			"name": "key3",
			"value": "C"
		}
	]
}

```

We want to transform the event into:

```auto
{
	"key1": "A",
	"key2": "B",
	"key3": "C"
}

```

Is there a filter plugin that is able to perform this action?  
If there is not, do we have to write a custom plugin?

---

<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: [May 26, 2020, 4:08pm UTC](https://discuss.elastic.co/t/transforming-array-of-objects/234366/2 "2020-05-26T16:08:31Z")

</div>

Use a ruby filter. [This](https://discuss.elastic.co/t/solved-split-filter-question-a-k-a-flatten-json-sub-array/130481/12) should get you started.

---

<div class="post-metadata">

### Author: ![AlessandroKP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alessandrokp/32/45312_2.png) [@AlessandroKP](https://discuss.elastic.co/u/AlessandroKP)
#### Post date: [June 1, 2020, 4:16pm UTC](https://discuss.elastic.co/t/transforming-array-of-objects/234366/3 "2020-06-01T16:16:20Z")

</div>

Hi @Badger,

thanks for you reply.

We applied the solution you pointed at and it worked like a charm!

Here it is the configuration of the Logstash pipeline:

```auto
input {
	...
}

filter {
	if [data] {
		ruby {
			code => '
			event.get("[data]").each { |dataElement|
				name = dataElement["name"]
				value = dataElement["value"]
				event.set( name, value)
			}
			'
		}		
	}
}

output {
	...
}

```

Thank you very much

Alessandro

---

<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 29, 2020, 4:16pm UTC](https://discuss.elastic.co/t/transforming-array-of-objects/234366/4 "2020-06-29T16:16:21Z")

</div>

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