# Merge two Json arrays in logstash+ruby

**URL:** <https://discuss.elastic.co/t/merge-two-json-arrays-in-logstash-ruby/312759>\
**Category:** Logstash\
**Created:** [August 24, 2022, 5:54am UTC](https://discuss.elastic.co/t/merge-two-json-arrays-in-logstash-ruby/312759 "2022-08-24T05:54:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deep08](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@deep08](https://discuss.elastic.co/u/deep08)\
**Post date:** [August 24, 2022, 5:54am UTC](https://discuss.elastic.co/t/merge-two-json-arrays-in-logstash-ruby/312759/1 "2022-08-24T05:54:56Z")

</div>

Hello ,

I want to merge two json array based on one id matching fields and create an new array in logstash , I have two Json array data1,data2 below -

"data1 "{  
"tenant":"0",  
"city":"FLORENCE",  
"id":"AXY798",  
"state":"KY",  
},  
{  
"tenant":"1",  
"city":"FLORENCE2",  
"id":"AXX123",  
"state":"KY",  
}  
"data2 "{  
"org":"teda",  
"id":"AXY798",  
"role":"Contact"  
},  
{  
"org":"partition",  
"id":"AXX123",  
"role":"Shared"  
}

Based on matching "id" , need to create a result json array:

"result "{  
"tenant":"0",  
"city":"FLORENCE",  
"id":"AXY798",  
"state":"KY",  
"role":"Contact",  
"org":"teda",  
},  
{  
"tenant":"1",  
"city":"FLORENCE2",  
"id":"AXX123",  
"state":"KY",  
"org":"partition",  
"role":"Shared"  
}

How to achieve this in logstash ..pls suggest

---

<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:** [September 21, 2022, 5:55am UTC](https://discuss.elastic.co/t/merge-two-json-arrays-in-logstash-ruby/312759/2 "2022-09-21T05:55:07Z")

</div>

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