# Convert a json nested string array to a flat string

**URL:** https://discuss.elastic.co/t/convert-a-json-nested-string-array-to-a-flat-string/116731
**Category:** Logstash
**Created:** [January 23, 2018, 7:08pm UTC](https://discuss.elastic.co/t/convert-a-json-nested-string-array-to-a-flat-string/116731 "2018-01-23T19:08:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hmed](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@hmed](https://discuss.elastic.co/u/hmed)
#### Post date: [January 23, 2018, 7:08pm UTC](https://discuss.elastic.co/t/convert-a-json-nested-string-array-to-a-flat-string/116731/1 "2018-01-23T19:08:43Z")

</div>

Hello,

I have this JSON

{  
"users": **"** [{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":3,"name":"david"}] **"** ,  
"date":"23/01/2017"  
}

even if I'm using the logstash filter:

filter {  
split {  
field =\> "users"  
}  
}

the message is stored in elastic as single event

**users** =\> [{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":3,"name":"david"}]  
**date** =\> 23/01/2017

question1: how I can convert the user field from string to a json array to have this

"users":[{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":1,"name":"david"}],  
"date":"23/01/2017"  
}

question 2: how I can store this nested json as a multiple json events in elastic

Expected output:

{  
"id":1,  
"name":"bob",  
"date":"23/01/2017"  
}

{  
"id":2,  
"name":"alice",  
"date":"23/01/2017"  
}

{  
"id":3,  
"name":"david",  
"date":"23/01/2017"  
}

Thanks in advance for your answer

---

<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: [January 23, 2018, 9:26pm UTC](https://discuss.elastic.co/t/convert-a-json-nested-string-array-to-a-flat-string/116731/2 "2018-01-23T21:26:00Z")

</div>

> question1: how I can convert the user field from string to a json array to have this

Use the json filter.

> question 2: how I can store this nested json as a multiple json events in elastic

Use the split filter.

---

<div class="post-metadata">

### Author: ![hmed](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@hmed](https://discuss.elastic.co/u/hmed)
#### Post date: [January 24, 2018, 2:48pm UTC](https://discuss.elastic.co/t/convert-a-json-nested-string-array-to-a-flat-string/116731/4 "2018-01-24T14:48:34Z")

</div>

Hello @magnusbaeck,

Many thanks for your answer.

Actually I'm using both json filter and split filters lik this  
json {  
source =\> "users"  
}  
split {  
field =\> "users"  
}

but I still have my users filed stored in elastic as string

users =\> [{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":3,"name":"david"}]

Do you have any idea on what is wrong with my logstash conf ?

this is the warn log I have in logstash:

Parsed JSON object/hash requires a target configuration option {:source=\>"users", :raw=\>" [{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":3,"name":"david"}]"}

Thanks in advance.

---

<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: [January 25, 2018, 10:08am UTC](https://discuss.elastic.co/t/convert-a-json-nested-string-array-to-a-flat-string/116731/5 "2018-01-25T10:08:59Z")

</div>

> Parsed JSON object/hash requires a target configuration option

You need to use the `target` option in the json filter to choose a field to store the array in.

---

<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: [February 22, 2018, 10:09am UTC](https://discuss.elastic.co/t/convert-a-json-nested-string-array-to-a-flat-string/116731/6 "2018-02-22T10:09:09Z")

</div>

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