# Help to parse JSON key value object

**URL:** <https://discuss.elastic.co/t/help-to-parse-json-key-value-object/78319>\
**Category:** Logstash\
**Created:** [March 13, 2017, 9:27am UTC](https://discuss.elastic.co/t/help-to-parse-json-key-value-object/78319 "2017-03-13T09:27:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hunk\_Huang](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@Hunk\_Huang](https://discuss.elastic.co/u/Hunk_Huang)\
**Post date:** [March 13, 2017, 9:27am UTC](https://discuss.elastic.co/t/help-to-parse-json-key-value-object/78319/1 "2017-03-13T09:27:39Z")

</div>

Hi Logstash Team.

I'd like to load data struct as below.  
INPUT:  
{  
"vmdata":{  
"vm1": "UP",  
"vm2": "Down",  
"vm3": "UP"  
.....  
}  
}

OUTPUT:  
event: vm1: "UP"  
event: vm2: "Down"  
....  
event: ...

Anybody can help? very appreciate!

---

<div class="post-metadata">

**Author:** ![Hunk\_Huang](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@Hunk\_Huang](https://discuss.elastic.co/u/Hunk_Huang)\
**Post date:** [March 15, 2017, 7:09am UTC](https://discuss.elastic.co/t/help-to-parse-json-key-value-object/78319/2 "2017-03-15T07:09:35Z")

</div>

Finally I am able to do it by ruby filter.

```
 ruby{
    init => "require 'json'"
    code => "
      event.get('[data][hostlist]').to_hash.each do |k,v|  
         newevent = event.clone
        newevent.set('vm', k)
        newevent.set('status' , v)
        newevent.remove('vmdata')
        new_event_block.call(newevent)        
      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:** [April 12, 2017, 7:09am UTC](https://discuss.elastic.co/t/help-to-parse-json-key-value-object/78319/3 "2017-04-12T07:09:59Z")

</div>

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