# How logstash uses add\_field to add a JSON array

**URL:** <https://discuss.elastic.co/t/how-logstash-uses-add-field-to-add-a-json-array/280640>\
**Category:** Logstash\
**Created:** [August 6, 2021, 10:42am UTC](https://discuss.elastic.co/t/how-logstash-uses-add-field-to-add-a-json-array/280640 "2021-08-06T10:42:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktpktr0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ktpktr0/32/87157_2.png) [@ktpktr0](https://discuss.elastic.co/u/ktpktr0)\
**Post date:** [August 6, 2021, 10:42am UTC](https://discuss.elastic.co/t/how-logstash-uses-add-field-to-add-a-json-array/280640/1 "2021-08-06T10:42:33Z")

</div>

The raw data are as follows

```auto
        "money快照" => [
            [0] "money:14683689,value:15105589,time:2021-07-27 23:50:54",
            [1] "money:14683689,value:15105589,time:2021-07-27 23:50:56"
        ],

```

The configuration file is as follows

```auto
       mutate {
                #gsub => ["jsonmsg","\[","\{"]
                #gsub => ["jsonmsg","\]","\}" ]
                remove_field => ["message"]
                add_field => {
                         "value1" => "%{[money快照][0]}"
                }
       }

```

give the result as follows

```auto
"value1" => "%{[money快照][0][value]}",

```

---

<div class="post-metadata">

**Author:** ![moziada](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@moziada](https://discuss.elastic.co/u/moziada)\
**Post date:** [August 6, 2021, 11:55am UTC](https://discuss.elastic.co/t/how-logstash-uses-add-field-to-add-a-json-array/280640/2 "2021-08-06T11:55:11Z")

</div>

You may need to use something like that

```auto
filter {
  if [money]{
    json {
      source => "money"
      target => "money"
    } 
  }
}

```

---

<div class="post-metadata">

**Author:** ![ktpktr0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ktpktr0/32/87157_2.png) [@ktpktr0](https://discuss.elastic.co/u/ktpktr0)\
**Post date:** [August 9, 2021, 7:27am UTC](https://discuss.elastic.co/t/how-logstash-uses-add-field-to-add-a-json-array/280640/4 "2021-08-09T07:27:11Z")

</div>

The result here has been parsed by the JSON plug-in. I now want to map the value field to the top-level field.

---

<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:** [September 6, 2021, 7:27am UTC](https://discuss.elastic.co/t/how-logstash-uses-add-field-to-add-a-json-array/280640/5 "2021-09-06T07:27:41Z")

</div>

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