# Logstash Ruby How to get fields of json array

**URL:** <https://discuss.elastic.co/t/logstash-ruby-how-to-get-fields-of-json-array/292867>\
**Category:** Logstash\
**Created:** [December 24, 2021, 7:03am UTC](https://discuss.elastic.co/t/logstash-ruby-how-to-get-fields-of-json-array/292867 "2021-12-24T07:03:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandima\_jayamina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandima_jayamina/32/99168_2.png) [@chandima\_jayamina](https://discuss.elastic.co/u/chandima_jayamina)\
**Post date:** [December 24, 2021, 7:03am UTC](https://discuss.elastic.co/t/logstash-ruby-how-to-get-fields-of-json-array/292867/1 "2021-12-24T07:03:05Z")

</div>

Hi I have an array

"testItem":["test1":"N", "test2":"", "test3":"xyz", "items":{"itemId":"123"},"test4","null"]

In here I want to extract the itemId from Json input through logstash how can i do it. I am new to logstash.

if [testItems][items][itemId] contains  
then copy =\> {"itemId"=\>%[testItems][items][itemId]}

thanks for help

---

<div class="post-metadata">

**Author:** ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)\
**Post date:** [December 27, 2021, 11:07pm UTC](https://discuss.elastic.co/t/logstash-ruby-how-to-get-fields-of-json-array/292867/2 "2021-12-27T23:07:19Z")

</div>

> [@chandima\_jayamina](#):
>
> "testItem":["test1":"N", "test2":"", "test3":"xyz", "items":{"itemId":"123"},"test4","null"]

This is [not valid JSON](https://onlinejsontools.com/highlight-json?input=%22testItem%22%3A%5B%22test1%22%3A%22N%22%2C%20%22test2%22%3A%22%22%2C%20%22test3%22%3A%22xyz%22%2C%20%22items%22%3A%7B%22itemId%22%3A%22123%22%7D%2C%22test4%22%2C%22null%22%5D&show-invisible=true&show-lines=true&match-brackets=true&highlight-line=true), and it is unclear to me what structure you are trying to express. Can you provide more detail about what you are attempting to accomplish?

---

<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:** [January 24, 2022, 11:07pm UTC](https://discuss.elastic.co/t/logstash-ruby-how-to-get-fields-of-json-array/292867/3 "2022-01-24T23:07:41Z")

</div>

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