# My array of objects has different keys, How can I chenged them to the same name?

**URL:** <https://discuss.elastic.co/t/my-array-of-objects-has-different-keys-how-can-i-chenged-them-to-the-same-name/307683>\
**Category:** Logstash\
**Created:** [June 20, 2022, 4:49pm UTC](https://discuss.elastic.co/t/my-array-of-objects-has-different-keys-how-can-i-chenged-them-to-the-same-name/307683 "2022-06-20T16:49:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvinacio](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jvinacio](https://discuss.elastic.co/u/jvinacio)\
**Post date:** [June 20, 2022, 4:49pm UTC](https://discuss.elastic.co/t/my-array-of-objects-has-different-keys-how-can-i-chenged-them-to-the-same-name/307683/1 "2022-06-20T16:49:10Z")

</div>

Hello,  
I have the following array:  
{  
"by\_hour" : [  
{  
"hour06" : "06",  
"nr\_artigos06" : 0,  
"caixa\_aberta06" : 0,  
"nr\_taloes06" : 1,  
"vendas\_liquidas06" : 0,  
"service\_time06" : null  
},  
{  
"nr\_taloes10" : 6,  
"service\_time10" : 256.024,  
"hour10" : "10",  
"nr\_artigos10" : 72,  
"caixa\_aberta10" : 1,  
"vendas\_liquidas10" : 105.67  
},  
{  
"nr\_taloes11" : 11,  
"service\_time11" : 246.67300000000003,  
"caixa\_aberta11" : 1,  
"nr\_artigos11" : 104,  
"vendas\_liquidas11" : 151.98,  
"hour11" : "11"  
}  
]  
}  
And I need to have the same variable name for each position to make a split, like the following:  
{  
"by\_hour" : [  
}  
"hour" : "06",  
"nr\_artigos" : 0,  
"caixa\_aberta" : 0,  
"nr\_taloes" : 1,  
"vendas\_liquidas" : 0,  
"service\_time" : null  
},  
{  
"nr\_taloes" : 6,  
"service\_time" : 256.024,  
"hour" : "10",  
"nr\_artigos" : 72,  
"caixa\_aberta" : 1,  
"vendas\_liquidas" : 105.67  
},  
{  
"nr\_taloes" : 11,  
"service\_time" : 246.67300000000003,  
"caixa\_aberta" : 1,  
"nr\_artigos" : 104,  
"vendas\_liquidas" : 151.98,  
"hour" : "11"  
}  
]  
}  
How can I make that happen?  
Thank you

---

<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:** [June 20, 2022, 6:00pm UTC](https://discuss.elastic.co/t/my-array-of-objects-has-different-keys-how-can-i-chenged-them-to-the-same-name/307683/2 "2022-06-20T18:00:57Z")

</div>

You would have to use a ruby filter if you want to change the field names. Something like

```
ruby {
    code => '
        byHour = event.get("by_hour")
        if byHour.is_a? Array
            byHour.each_index { |x|
                byHour[x].transform_keys! { |k| k.gsub(/\d+$/, "") }
            }
            event.set("by_hour", byHour)
        end
    '
}
```

---

<div class="post-metadata">

**Author:** ![jvinacio](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jvinacio](https://discuss.elastic.co/u/jvinacio)\
**Post date:** [June 21, 2022, 10:53am UTC](https://discuss.elastic.co/t/my-array-of-objects-has-different-keys-how-can-i-chenged-them-to-the-same-name/307683/3 "2022-06-21T10:53:33Z")

</div>

Thank you very much! It solved \<3

---

<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:** [July 19, 2022, 10:54am UTC](https://discuss.elastic.co/t/my-array-of-objects-has-different-keys-how-can-i-chenged-them-to-the-same-name/307683/4 "2022-07-19T10:54:14Z")

</div>

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