# I need help in extracting specific value from json array field

**URL:** <https://discuss.elastic.co/t/i-need-help-in-extracting-specific-value-from-json-array-field/93751>\
**Category:** Logstash\
**Created:** [July 19, 2017, 11:35am UTC](https://discuss.elastic.co/t/i-need-help-in-extracting-specific-value-from-json-array-field/93751 "2017-07-19T11:35:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ea1987](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ea1987/32/51356_2.png) [@ea1987](https://discuss.elastic.co/u/ea1987)\
**Post date:** [July 19, 2017, 11:35am UTC](https://discuss.elastic.co/t/i-need-help-in-extracting-specific-value-from-json-array-field/93751/1 "2017-07-19T11:35:23Z")

</div>

Hi guys,  
I'm working on a json log. I have extracted correctly json message from its entries and parsed it via json plugin in this way:

> grok {  
> patterns\_dir =\> ["/home/elastic/ELASTIC\_55/logstash-5.5.0/config/patterns/extrapatterns"]  
> match =\> { "text" =\> "%{CUSTOM\_JSON:json\_request}" }  
> }

> json {  
> source =\> "json\_request"  
> tag\_on\_failure =\> ["errore\_parser\_json"]  
> target =\> "json\_message"  
> }

This is what I get from logstash log (I set them to --debug):

> json\_message" =\> [  
> [0] {  
> "a\_cruid" =\> "00-06",  
> "descrizione" =\> "test\_descrizione",  
> "fornitore" =\> "SARBEC",  
> "ean" =\> "800291332",  
> "merceologia" =\> "tipo\_merceologia",  
> "pvm" =\> "ap723",  
> "operation" =\> "richiesta\_codifica\_success"  
> }  
> ]

An array type field. That's fine.

What I would like to do now is extracting a\_cruid field's value and set it to a new correlazione field.  
I have read event api documentation but, in my opinion, it's missing some detailed examples. I tried to write down a ruby filter code in these 2 ways, but I always get nil value

> ruby {  
> code =\> 'event.set("correlazione", event.get("[json\_message][1]"))'  
> }

> ruby {  
> code =\> 'event.set("correlazione", event.get("[json\_message][a\_cruid]"))'  
> }

Can you plean help me in understanding better in what I'm wrong and suggest me the best approach to this?  
Thanks in advance,

Andrea

---

<div class="post-metadata">

**Author:** ![ea1987](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ea1987/32/51356_2.png) [@ea1987](https://discuss.elastic.co/u/ea1987)\
**Post date:** [July 19, 2017, 3:48pm UTC](https://discuss.elastic.co/t/i-need-help-in-extracting-specific-value-from-json-array-field/93751/2 "2017-07-19T15:48:54Z")

</div>

I have found the solution:

> ruby {  
> code =\> 'event.set("a\_cruid", event.get("json\_message[0][a\_cruid]"))'  
> }

Thank you anyway!

Andrea

---

<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:** [August 16, 2017, 3:49pm UTC](https://discuss.elastic.co/t/i-need-help-in-extracting-specific-value-from-json-array-field/93751/3 "2017-08-16T15:49:08Z")

</div>

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