# Help with embedded JSON flatten - Ruby Filter

**URL:** <https://discuss.elastic.co/t/help-with-embedded-json-flatten-ruby-filter/166442>\
**Category:** Logstash\
**Created:** [January 30, 2019, 10:42pm UTC](https://discuss.elastic.co/t/help-with-embedded-json-flatten-ruby-filter/166442 "2019-01-30T22:42:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frrrrrunkis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frrrrrunkis/32/42750_2.png) [@Frrrrrunkis](https://discuss.elastic.co/u/Frrrrrunkis)\
**Post date:** [January 30, 2019, 10:42pm UTC](https://discuss.elastic.co/t/help-with-embedded-json-flatten-ruby-filter/166442/1 "2019-01-30T22:42:52Z")

</div>

HI All

I have been struggling with this json structure for some time now. Im looking for assistance in flattening this json message. I assume that ruby iteration would be needed here but all the examples I try dont seem to work for me. The data comes from IBM API COnnect event export as a json document.

Here is some data. It should be noted that number of items in the embedded jsons are dynamic. Id like to flatten the response\_http\_headers in this example.

{  
"api\_name": "app",  
"status\_code": "200 OK",  
"request\_method": "GET",  
"developer\_org\_name": "dev",  
"http\_user\_agent": "Healthcheck",  
"resource\_path": "get",  
"@version": "1",  
"response\_http\_headers": [  
{  
"Content-Type": "application/json"  
},  
{  
"Date": "Mon, 19 Nov 2018 15:49:21 GMT"  
},  
{  
"X-Global-Transaction-ID": "4538538753"  
},  
{  
"User-Agent": "IBM-APIConnect/5.0"  
},  
{  
"accept": "application/json"  
},  
{  
"Via": "1.1 AQAAACbdihddsQb8-"  
},  
{  
"X-Client-IP": "107.1.22.4"  
},  
{  
"Access-Control-Expose-Headers": "APIm-Debug-Trans-Id, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-Global-Transaction-ID"  
},  
{  
"Access-Control-Allow-Origin": "\*"  
},  
{  
"Access-Control-Allow-Methods": "GET"  
},  
{  
"Access-Control-Allow-Credentials": "false"  
}  
],  
"org\_name": "org"  
}

Thanks

---

<div class="post-metadata">

**Author:** ![Frrrrrunkis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frrrrrunkis/32/42750_2.png) [@Frrrrrunkis](https://discuss.elastic.co/u/Frrrrrunkis)\
**Post date:** [February 1, 2019, 8:53pm UTC](https://discuss.elastic.co/t/help-with-embedded-json-flatten-ruby-filter/166442/2 "2019-02-01T20:53:51Z")

</div>

utilized this script from Chris Lyons

> <https://gist.github.com/cjlyons81/8f47a281934c8e7c040d7bf8985db331>

found this topic - [Ruby filter for parsing deeply nested JSON in pipeline](https://discuss.elastic.co/t/ruby-filter-for-parsing-deeply-nested-json-in-pipeline/161050/6)

---

<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:** [March 1, 2019, 8:54pm UTC](https://discuss.elastic.co/t/help-with-embedded-json-flatten-ruby-filter/166442/3 "2019-03-01T20:54:03Z")

</div>

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