# Parsing nested JSON fields to separate fields

**URL:** <https://discuss.elastic.co/t/parsing-nested-json-fields-to-separate-fields/249973>\
**Category:** Logstash\
**Created:** [September 25, 2020, 11:40am UTC](https://discuss.elastic.co/t/parsing-nested-json-fields-to-separate-fields/249973 "2020-09-25T11:40:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ottramst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ottramst/32/69631_2.png) [@ottramst](https://discuss.elastic.co/u/ottramst)\
**Post date:** [September 25, 2020, 11:40am UTC](https://discuss.elastic.co/t/parsing-nested-json-fields-to-separate-fields/249973/1 "2020-09-25T11:40:36Z")

</div>

Hello everyone!

I need to create a Logstash configuration that allows me to parse nested JSON fields to single fields.

Input event looks like this:

```auto
{
	"cloud": {
		"instance": {
			"id": "XXXX"
		},
		"machine": {
			"type": "t3a.large"
		},
		"provider": "aws",
		"availability_zone": "eu-central-1a",
		"region": "eu-central-1",
		"account": {
			"id": "XXXX"
		},
		"image": {
			"id": "XXXX"
		}
	}
}

```

And the output I would like to have is to have every nested value parsed to fields along with parent field names included in the final field name like so:

```auto
"cloud_instance_id" => "XXX"
"cloud_machine_type" => "XXX"

```

I have tried with just using the add\_field filter and creating a new field using the value like so:

```auto
mutate {
  add_field => {
    "cloud_account_id" => "%{[cloud][account][id]}"
  }
}

```

But I'm looking to find out if there is a way to do this by using the Ruby filter and creating a reusable script with input parameters.

Any help is appreciated!

---

<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:** [September 25, 2020, 2:06pm UTC](https://discuss.elastic.co/t/parsing-nested-json-fields-to-separate-fields/249973/2 "2020-09-25T14:06:25Z")

</div>

See [this](https://discuss.elastic.co/t/indent-any-json-file-nested-fields-and-make-it-flat/194447/2) answer.

---

<div class="post-metadata">

**Author:** ![ottramst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ottramst/32/69631_2.png) [@ottramst](https://discuss.elastic.co/u/ottramst)\
**Post date:** [September 25, 2020, 2:51pm UTC](https://discuss.elastic.co/t/parsing-nested-json-fields-to-separate-fields/249973/3 "2020-09-25T14:51:51Z")

</div>

Thank you! Case closed.

---

<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:** [October 23, 2020, 2:51pm UTC](https://discuss.elastic.co/t/parsing-nested-json-fields-to-separate-fields/249973/4 "2020-10-23T14:51:51Z")

</div>

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