# How to parse nested json events

**URL:** <https://discuss.elastic.co/t/how-to-parse-nested-json-events/292039>\
**Category:** Logstash\
**Created:** [December 15, 2021, 6:53pm UTC](https://discuss.elastic.co/t/how-to-parse-nested-json-events/292039 "2021-12-15T18:53:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anusha\_Kusanghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anusha_kusanghi/32/98109_2.png) [@Anusha\_Kusanghi](https://discuss.elastic.co/u/Anusha_Kusanghi)\
**Post date:** [December 15, 2021, 6:53pm UTC](https://discuss.elastic.co/t/how-to-parse-nested-json-events/292039/1 "2021-12-15T18:53:21Z")

</div>

Hello!  
I have nested json objects like this :

```auto
{
  "_index": "impe_logs-2021.11.19-1",
  "_type": "_doc",
  "_id": "tyu",
  "_version": 1,
  "_score": null,
  "_source": {
    "port": 54640,
    "impe": {
      "abp": {
        "random_id": "",
        "policy_id": "91",
        "token_id": "",
        "bot_violations": [
          "known_violator_header_id",
          "known_violator_user_agent",
          "no_token",
          "suspicious_user_agent"a
        ]}
"client": {
      "geo": {
        "name": ""
      },
      "domain": "",
      "ip": "1.2.3.4"
    }
	}}}

```

when im trying to store in Elasticsearch :  
impe.abp.policy\_id 91 but i want it to be stored as policy\_id 91  
and client.geo.name want it as **client geo name**

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [December 21, 2021, 5:27pm UTC](https://discuss.elastic.co/t/how-to-parse-nested-json-events/292039/2 "2021-12-21T17:27:48Z")

</div>

You can use the [mutate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) filter to copy the contents of one field into another (under a different name) or rename the field all together.

For example:

```auto
filter {
   mutate {
      rename => { "[impe][abp][policy_id]" => "policy_id" 
                             "[client][geo][name]" => "client_geo_name"}
   
}

```

However, I would caution that you should try and conform to [ECS](https://www.elastic.co/guide/en/ecs/current/index.html) as much as possible 🙂

---

<div class="post-metadata">

**Author:** ![Anusha\_Kusanghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anusha_kusanghi/32/98109_2.png) [@Anusha\_Kusanghi](https://discuss.elastic.co/u/Anusha_Kusanghi)\
**Post date:** [December 22, 2021, 5:01am UTC](https://discuss.elastic.co/t/how-to-parse-nested-json-events/292039/3 "2021-12-22T05:01:09Z")

</div>

Hello @AquaX ,  
Thanks for the help ,yes even mutate works.  
but found a solution from other discussion:

```auto
ruby {
         code => '
                event.get("[imperva][abp]").each { |k, v|
                event.set(k,v)
                }
         event.remove("[imperva][abp]")
}

```

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [December 22, 2021, 2:02pm UTC](https://discuss.elastic.co/t/how-to-parse-nested-json-events/292039/4 "2021-12-22T14:02:10Z")

</div>

Ahh! I did not understand that you wanted to do this programmatically for a dynamic list. Glad you got it figured out!

---

<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:** [January 19, 2022, 2:02pm UTC](https://discuss.elastic.co/t/how-to-parse-nested-json-events/292039/5 "2022-01-19T14:02:44Z")

</div>

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