# Parsing dictionary into json file

**URL:** <https://discuss.elastic.co/t/parsing-dictionary-into-json-file/191386>\
**Category:** Logstash\
**Created:** [July 19, 2019, 11:49am UTC](https://discuss.elastic.co/t/parsing-dictionary-into-json-file/191386 "2019-07-19T11:49:32Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [July 19, 2019, 1:18pm UTC](https://discuss.elastic.co/t/parsing-dictionary-into-json-file/191386/4 "2019-07-19T13:18:06Z")

</div>

> [@saisimo02](#):
>
> {"id":"\*\*\*\*\*\*\*","name":"test","alarm":{"error":2,"warning":3}}

You could try this

```
    ruby {
        code => '
            a = []
            event.get("alarm").each { |k, v|
                h = Hash.new
                h["alarmLevel"] = k
                h["alarmValue"] = v
                a << h
            }
            event.remove("alarm")
            event.set("alarm", a)
        '
    }
    split { field => "alarm" }

```

If you need to then move the contents of alarm to the root level look at [this](https://discuss.elastic.co/t/how-to-dynamically-move-nested-key-value-to-root-level/180006/2).

---

_[View the full topic](https://discuss.elastic.co/t/parsing-dictionary-into-json-file/191386)._
