# Can i construct an array of hashes from array of strings

**URL:** <https://discuss.elastic.co/t/can-i-construct-an-array-of-hashes-from-array-of-strings/122383>\
**Category:** Logstash\
**Created:** [March 3, 2018, 6:49pm UTC](https://discuss.elastic.co/t/can-i-construct-an-array-of-hashes-from-array-of-strings/122383 "2018-03-03T18:49:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david\_reynolds](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_reynolds/32/28306_2.png) [@david\_reynolds](https://discuss.elastic.co/u/david_reynolds)\
**Post date:** [March 3, 2018, 6:49pm UTC](https://discuss.elastic.co/t/can-i-construct-an-array-of-hashes-from-array-of-strings/122383/1 "2018-03-03T18:49:43Z")

</div>

Using Logstash 5.6.

Given a single event (a string) that contains a number of lines like **(a)** I need to create an array of hashes to produce the output **(b)**

so far I can produce an array of strings using the mutate filter  
mutate { copy =\> { "message" =\> "errors"} }  
mutate {  
gsub =\> ["[errors]", "ERROR", "|"]  
split =\> { "[errors]" =\> "|" } # creates an array of strings  
}

But I can't figure out how to convert the array of strings into an array of hashes. Can't find any equivalent topics.

**(a)** message =\> "ERROR Code=123, SubCode=XYZ\r\nERROR Code=121, SubCode=XJA\r\n"  
nb: ... (variable number of errors)

**(b)** the final output (rubydebug) would look like:  
{  
"message" =\> "ERROR Code=123, SubCode=XYZ\r\nERROR Code=121, SubCode=XJA\r\n",  
"@timestamp" =\> 2018-02-28T15:14:40.150Z,  
"errors" =\> [  
[0] {Code=\>"123", SubCode=\>"XYZ" },  
[1] {Code=\>"121", SubCode=\>"XJA"}  
]  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 4, 2018, 8:19pm UTC](https://discuss.elastic.co/t/can-i-construct-an-array-of-hashes-from-array-of-strings/122383/2 "2018-03-04T20:19:21Z")

</div>

I think you'll have to write some custom code in a ruby filter.

---

<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 1, 2018, 8:19pm UTC](https://discuss.elastic.co/t/can-i-construct-an-array-of-hashes-from-array-of-strings/122383/3 "2018-04-01T20:19:38Z")

</div>

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