# Parsing array of json objects

**URL:** <https://discuss.elastic.co/t/parsing-array-of-json-objects/357138>\
**Category:** Logstash\
**Created:** [April 10, 2024, 12:07pm UTC](https://discuss.elastic.co/t/parsing-array-of-json-objects/357138 "2024-04-10T12:07:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonukowlwar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sonukowlwar/32/133416_2.png) [@sonukowlwar](https://discuss.elastic.co/u/sonukowlwar)\
**Post date:** [April 10, 2024, 12:07pm UTC](https://discuss.elastic.co/t/parsing-array-of-json-objects/357138/1 "2024-04-10T12:07:49Z")

</div>

Hello ,

I am new to logstash and would like to parse the below json file and add three seperate fields header1 and header2 and header3. Any suggestion on how to do it

{  
"name": "abc",  
"headers": [  
{  
"header1": "value1"  
},  
{  
"header2": "value2"  
},  
{  
"header3": "value3"  
}  
]  
}

---

<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:** [April 10, 2024, 4:42pm UTC](https://discuss.elastic.co/t/parsing-array-of-json-objects/357138/2 "2024-04-10T16:42:40Z")

</div>

You could try

```
    ruby {
        code => '
            h = event.remove("headers")
            if h
                h.each { |x|
                    x.each { |k, v|
                        event.set(k, v)
                    }
                }
            end
        '
    }

```

Add error checking as needed.
