# Nested json parsing - data from api

**URL:** <https://discuss.elastic.co/t/nested-json-parsing-data-from-api/171865>\
**Category:** Elasticsearch\
**Created:** [March 12, 2019, 5:59am UTC](https://discuss.elastic.co/t/nested-json-parsing-data-from-api/171865 "2019-03-12T05:59:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinaypn](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@vinaypn](https://discuss.elastic.co/u/vinaypn)\
**Post date:** [March 12, 2019, 5:59am UTC](https://discuss.elastic.co/t/nested-json-parsing-data-from-api/171865/1 "2019-03-12T05:59:34Z")

</div>

Hi Team,

Below is my input file.

{  
"sessionHost": "127.0.0.1",  
"sysrep\_physicaldiskspacedata": {  
"links": [{  
"href": "[https://127.0.0.1:8080/api/v1/systemreporter/attime/physicaldiskspacedata/hourly](https://127.0.0.1:8080/api/v1/systemreporter/attime/physicaldiskspacedata/hourly)",  
"rel": "self"  
}]  
}  
}

Logstash config is:  
input {  
file {  
path =\> ['/home/sample.json']  
start\_position =\> "beginning"  
tags =\> ['sample']  
type =\> "sample"  
codec =\> "json"  
}  
}

filter{  
if [type] == "sample" {  
json {  
source =\> "message"  
}  
ruby {  
code =\> '  
arrayOfEvents = Array.new()  
ts = event.get("sysrep\_physicaldiskspacedata")  
ts.each do |data|

```
            arrayOfEvents.push(data)
        end
        event.set("event",arrayOfEvents)
    '
    remove_field => ["sysrep_physicaldiskspacedata"]
}
split {
    field => 'event'
}

    }

```

}

output {  
stdout {  
codec =\> "rubydebug"  
}  
}

Error:  
[ERROR] 2019-03-12 06:41:44.276 [Ruby-0-Thread-7: :1] ruby - Ruby exception occurred: undefined method `each' for nil:NilClass [ERROR] 2019-03-12 06:41:44.316 [Ruby-0-Thread-6: :1] ruby - Ruby exception occurred: undefined method`each' for nil:NilClass  
[ERROR] 2019-03-12 06:41:44.323 [Ruby-0-Thread-4: :1] ruby - Ruby exception occurred: undefined method `each' for nil:NilClass  
[WARN] 2019-03-12 06:41:44.354 [Ruby-0-Thread-4: :1] split - Only String and Array types are splittable. field:event is of type = NilClass

How to fix this?

---

<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 9, 2019, 5:59am UTC](https://discuss.elastic.co/t/nested-json-parsing-data-from-api/171865/2 "2019-04-09T05:59:34Z")

</div>

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