# Issue with json arrays

**URL:** <https://discuss.elastic.co/t/issue-with-json-arrays/185374>\
**Category:** Logstash\
**Created:** [June 12, 2019, 9:45am UTC](https://discuss.elastic.co/t/issue-with-json-arrays/185374 "2019-06-12T09:45:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moti.mor](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@moti.mor](https://discuss.elastic.co/u/moti.mor)\
**Post date:** [June 12, 2019, 9:45am UTC](https://discuss.elastic.co/t/issue-with-json-arrays/185374/1 "2019-06-12T09:45:08Z")

</div>

Hi guys,

i have issue with parssing json with logstash.  
here is my logstash configuration:  
input {  
beats {  
port =\> "5044"  
}  
}

filter {  
ruby {  
init =\> "  
def arrays\_to\_hash(h)  
h.each do |k,v|  
# If v is nil, an array is being iterated and the value is k.  
# If v is not nil, a hash is being iterated and the value is v.  
value = v || k  
if value.is\_a?(Array)  
# "value" is replaced with "value\_hash" later.  
value\_hash = {}  
value.each\_with\_index do |v, i|  
value\_hash[i.to\_s] = v  
end  
h[k] = value\_hash  
end

```
        if value.is_a?(Hash) || value.is_a?(Array)
          arrays_to_hash(value)
        end
      end
    end
  "
  code => "arrays_to_hash(event.to_hash)"
 }

```

}

output {  
elasticsearch {  
hosts =\> ["x.x.x.x:9200"]  
}  
}

attached an error when restarting the service:  
[2019-06-12T12:44:34,939][ERROR][logstash.agent] Failed to execute action {:action=\>LogStash::PipelineAction::Create/pipeline\_id:main, :exception=\>"LogStash::ConfigurationError", :message=\>"Expected one of #, {, } at line 17, column 20 (byte 394) after filter {\n ruby {\n init =\> "\n def arrays\_to\_hash(h)\n h.each do |k,v|\n # If v is nil, an array is being iterated and the value is k.\n # If v is not nil, a hash is being iterated and the value is v.\n value = v || k\n if value.is\_a?(Array)\n # "", :backtrace=\>["/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:41:in `compile_imperative'", "/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:49:in`compile\_graph'", "/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:11:in `block in compile_sources'", "org/jruby/RubyArray.java:2577:in`map'", "/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:10:in `compile_sources'", "org/logstash/execution/AbstractPipelineExt.java:151:in`initialize'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:22:in `initialize'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:90:in`initialize'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline\_action/create.rb:43:in `block in execute'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:96:in`block in exclusive'", "org/jruby/ext/thread/Mutex.java:165:in `synchronize'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:96:in`exclusive'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline\_action/create.rb:39:in `execute'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:334:in`block in converge\_state'"]}

please advise thank you all!!!

---

<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:** [June 12, 2019, 1:19pm UTC](https://discuss.elastic.co/t/issue-with-json-arrays/185374/2 "2019-06-12T13:19:35Z")

</div>

> [@moti.mor](#):
>
> ```
> # "value" is replaced with "value_hash" later.
> 
> ```

You need to use \" rather than ", or else surround your init block with ' rather than ".

---

<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:** [July 10, 2019, 1:19pm UTC](https://discuss.elastic.co/t/issue-with-json-arrays/185374/3 "2019-07-10T13:19:36Z")

</div>

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