# Using Ruby to rename and flatten dynamic json input

**URL:** <https://discuss.elastic.co/t/using-ruby-to-rename-and-flatten-dynamic-json-input/276438>\
**Category:** Logstash\
**Created:** [June 19, 2021, 3:19pm UTC](https://discuss.elastic.co/t/using-ruby-to-rename-and-flatten-dynamic-json-input/276438 "2021-06-19T15:19:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackberrySherbet](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@blackberrySherbet](https://discuss.elastic.co/u/blackberrySherbet)\
**Post date:** [June 19, 2021, 3:19pm UTC](https://discuss.elastic.co/t/using-ruby-to-rename-and-flatten-dynamic-json-input/276438/1 "2021-06-19T15:19:54Z")

</div>

I have a variable in Logstash that holds some nested JSON.  
I do not know the structure or name of the keys (they are dynamic). I need to flatten this JSON into a single level and append a "nested\_" to all the keys that were nested. I am guessing I have to do this with Ruby? I have been trying different things and I haven't been able to get something working. I'd appreciate any help or hints.

Thanks

---

<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 19, 2021, 4:31pm UTC](https://discuss.elastic.co/t/using-ruby-to-rename-and-flatten-dynamic-json-input/276438/2 "2021-06-19T16:31:00Z")

</div>

There is an example of doing that [here](https://discuss.elastic.co/t/indent-any-json-file-nested-fields-and-make-it-flat/194447/2).

---

<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 17, 2021, 4:31pm UTC](https://discuss.elastic.co/t/using-ruby-to-rename-and-flatten-dynamic-json-input/276438/3 "2021-07-17T16:31:18Z")

</div>

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