# Extract field from json to the top-level

**URL:** <https://discuss.elastic.co/t/extract-field-from-json-to-the-top-level/84667>\
**Category:** Logstash\
**Created:** [May 5, 2017, 7:11am UTC](https://discuss.elastic.co/t/extract-field-from-json-to-the-top-level/84667 "2017-05-05T07:11:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![babayotakun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babayotakun/32/64403_2.png) [@babayotakun](https://discuss.elastic.co/u/babayotakun)\
**Post date:** [May 5, 2017, 7:11am UTC](https://discuss.elastic.co/t/extract-field-from-json-to-the-top-level/84667/1 "2017-05-05T07:11:44Z")

</div>

I have a json with the dynamic field, something like that:  
`{ field1: "value1", dynamicField: { innerField1: "...", innerField2: "...", ... } }`  
How can I extract all contents from dynamicField to the top level of message?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 5, 2017, 7:18am UTC](https://discuss.elastic.co/t/extract-field-from-json-to-the-top-level/84667/2 "2017-05-05T07:18:16Z")

</div>

You'll have to use a ruby filter for this. I'm pretty sure examples have been posted in the past, either here or on Stackoverflow.

---

<div class="post-metadata">

**Author:** ![babayotakun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babayotakun/32/64403_2.png) [@babayotakun](https://discuss.elastic.co/u/babayotakun)\
**Post date:** [May 5, 2017, 8:30am UTC](https://discuss.elastic.co/t/extract-field-from-json-to-the-top-level/84667/3 "2017-05-05T08:30:19Z")

</div>

Yes, it can be achieved with the ruby filter, thatnks.  
Here it it is the config, if someone curious:

```
filter { ruby {
code => "
  begin
    dynamicField= event.get('dynamicField')
    if dynamicField!= NIL
      dynamicField.keys.each{|key|
        event.set(key, dynamicField[key])
      }
      event.remove('dynamicField')
    end
  end
" }}
```

---

<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:** [June 2, 2017, 8:30am UTC](https://discuss.elastic.co/t/extract-field-from-json-to-the-top-level/84667/4 "2017-06-02T08:30:52Z")

</div>

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