# Logstash ruby json parser

**URL:** <https://discuss.elastic.co/t/logstash-ruby-json-parser/125770>\
**Category:** Logstash\
**Created:** [March 27, 2018, 2:02pm UTC](https://discuss.elastic.co/t/logstash-ruby-json-parser/125770 "2018-03-27T14:02:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![darshan](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@darshan](https://discuss.elastic.co/u/darshan)\
**Post date:** [March 27, 2018, 2:02pm UTC](https://discuss.elastic.co/t/logstash-ruby-json-parser/125770/1 "2018-03-27T14:02:38Z")

</div>

Hi i am trying to parse a json string in logstash ruby filter.

My logstash ruby code is.  
ruby {  
code =\> "jsondata = event.get('[json]')  
puts jsondata  
jsondata.to\_hash  
jsondata.each { |key, value|  
puts key  
puts value  
event.set(['json']['#{key}']['command\_ip'], key)  
}  
"  
}

and the input json to the ruby is

{  
"182.1xx.xx.xx": {  
"status": "Failed",  
"result": "Error String"  
},  
"192.1xx.xx.xx": {  
"status": "Success"  
}  
}

and i am expecting the output from this as below

{  
"182.1xx.xx.xx": {  
"host" : "182.1xx.xx.xx"  
"status": "Failed",  
"result": "Error String"  
},  
"192.1xx.xx.xx": {  
"host" : "192.1xx.xx.xx"  
"status": "Success"  
}  
}

but when i try to parse the above json i am getting exception saying "Ruby exception occurred: no implicit conversion of String into Integer".

Please help me out to solve this issue. Thanks..

---

<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 24, 2018, 2:03pm UTC](https://discuss.elastic.co/t/logstash-ruby-json-parser/125770/2 "2018-04-24T14:03:04Z")

</div>

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