# Flatten json array in Logstash

**URL:** <https://discuss.elastic.co/t/flatten-json-array-in-logstash/399>\
**Category:** Logstash\
**Created:** [May 8, 2015, 1:21pm UTC](https://discuss.elastic.co/t/flatten-json-array-in-logstash/399 "2015-05-08T13:21:46Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rmoff](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rmoff/32/20212_2.png) [@rmoff](https://discuss.elastic.co/u/rmoff)\
**Post date:** [July 21, 2016, 9:47am UTC](https://discuss.elastic.co/t/flatten-json-array-in-logstash/399/7 "2016-07-21T09:47:31Z")

</div>

I just came across this post again via a Google search when looking to solve exactly the same issue. On the basis that others might too, I wanted to add to it some ruby code that might be useful for others doing this, that will combine the elements of an array into a single string:

```
ruby {
code => 'event["hashtags_array"] = event["[entities][hashtags]"].collect { |m| m["text"] } unless event["[entities][hashtags]"].nil?
event["hashtags_list"] = event["hashtags_array"].join(",") unless event["[hashtags_array]"].nil?'
}

```

The first line is just as @jordansissel provided me above; the second line is a hack together that I figured out but seems to work. Example input:

```
  "entities": {
    "hashtags": [
      {
        "text": "Iran",
        "indices": [
          18,
          23
        ]
      },
      {
        "text": "News",
        "indices": [
          24,
          29
        ]
      }
    ],

```

Example output:

```
          "hashtags_array" => [
    [0] "Iran",
    [1] "News"
],
            "hashtags_list" => "Iran,News",
```

---

_[View the full topic](https://discuss.elastic.co/t/flatten-json-array-in-logstash/399)._
