# How to parse array of arrays inside json

**URL:** <https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658>\
**Category:** Logstash\
**Created:** [March 15, 2017, 8:53am UTC](https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658 "2017-03-15T08:53:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaishnavi](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@vaishnavi](https://discuss.elastic.co/u/vaishnavi)\
**Post date:** [March 15, 2017, 8:53am UTC](https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658/1 "2017-03-15T08:53:14Z")

</div>

Hi  
I am trying to parse json which contains arrays within arrays and want it give them as seperate records in elasticsearch using logstash

* * *

My input is

> [{"root":[{"data":[{"id1" : [{"value":"1"}],"id2" : [{"value":"1"}]}]}]}]

* * *

My code

> input {  
> stdin{  
> codec=\>"json"  
> }  
> }  
> filter {  
> json{  
> source=\>"message"  
> }  
> split{  
> field=\>"[root]"  
> }  
> split{  
> field=\>"[root][data]"  
> }  
> split{  
> field=\>"[root][data][id1]"  
> }  
> split{  
> field=\>"[root][data][id2]"  
> }
> 
> }

> output {  
> stdout{  
> codec =\> rubydebug  
> }

* * *

I am currently getting the output as

> {  
> "@timestamp" =\> 2017-03-15T14:19:11.720Z,  
> "root" =\> {  
> "data" =\> {  
> "id2" =\> {  
> "value" =\> "1"  
> },  
> "id1" =\> {  
> "value" =\> "1"  
> }  
> }  
> },  
> "@version" =\> "1",  
> "host" =\> "localhost.localdomain"  
> }

* * *

My desired output should contains two records in elasticsearch as

> {  
> "@timestamp" =\> 2017-03-15T14:19:11.720Z,  
> "root" =\> {  
> "data" =\> {  
> "id1" =\> {  
> "value" =\> "1"  
> }  
> }  
> },  
> "@version" =\> "1",  
> "host" =\> "localhost.localdomain"  
> }, {  
> "@timestamp" =\> 2017-03-15T14:19:11.720Z,  
> "root" =\> {  
> "data" =\> {  
> "id2" =\> {  
> "value" =\> "1"  
> }  
> }  
> },  
> "@version" =\> "1",  
> "host" =\> "localhost.localdomain"  
> }

Could any one help me to do this,

Thanks in advance

---

<div class="post-metadata">

**Author:** ![whyapenny](https://avatars.discourse-cdn.com/v4/letter/w/90db22/32.png) [@whyapenny](https://discuss.elastic.co/u/whyapenny)\
**Post date:** [March 16, 2017, 4:43am UTC](https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658/2 "2017-03-16T04:43:31Z")

</div>

confusion here as to why you would want to store the record as two different documents. immediately i do not see a need for that, nor a way to do so - though there may be.

perhaps you have overcomplicated it? If you could give a bit of background it could help me understand what you are ultimately attempting to achieve and perhaps provide solution/alternative.

---

<div class="post-metadata">

**Author:** ![vaishnavi](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@vaishnavi](https://discuss.elastic.co/u/vaishnavi)\
**Post date:** [March 16, 2017, 5:19am UTC](https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658/3 "2017-03-16T05:19:39Z")

</div>

Thanks for the reply

My json structure is dynamic i.e key names and values names will always change. I dont have any fixed json structure

If I store in same document then it will be difficult for me to visualize the data because it contains different names for different records so I need to store them in seperate records with same name which I will achieve by aliasing

It would be helpful if I get a proper solution to achieve this as I am new to logstash

Thanks in advance

---

<div class="post-metadata">

**Author:** ![whyapenny](https://avatars.discourse-cdn.com/v4/letter/w/90db22/32.png) [@whyapenny](https://discuss.elastic.co/u/whyapenny)\
**Post date:** [March 16, 2017, 5:25am UTC](https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658/4 "2017-03-16T05:25:07Z")

</div>

perhaps multiple examples of some sample data and visualizations you are attemtping to achieve might help here, but overall i dont see it being difficult to visualize if they're in the same document.

---

<div class="post-metadata">

**Author:** ![vaishnavi](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@vaishnavi](https://discuss.elastic.co/u/vaishnavi)\
**Post date:** [March 16, 2017, 6:24am UTC](https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658/5 "2017-03-16T06:24:55Z")

</div>

My sample data contains many json formats as

> [{"root":[{"data":[{"id1" : [{"value":1}],"id2" : [{"value":1}]}]}]}]

> [{"head":[{"dt":[{"id4" : [{"value":1}],"id6" : [{"value":1}]}]}]}]

and My visualization must contain (say) sum of all value i.e my result should be 4

How can I achieve this

---

<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 13, 2017, 6:25am UTC](https://discuss.elastic.co/t/how-to-parse-array-of-arrays-inside-json/78658/6 "2017-04-13T06:25:06Z")

</div>

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