# Filebeat output empty JSON array as "null" instead of "\[\]"

**URL:** <https://discuss.elastic.co/t/filebeat-output-empty-json-array-as-null-instead-of/276604>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [June 22, 2021, 4:45am UTC](https://discuss.elastic.co/t/filebeat-output-empty-json-array-as-null-instead-of/276604 "2021-06-22T04:45:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ijingo](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ijingo](https://discuss.elastic.co/u/ijingo)\
**Post date:** [June 22, 2021, 4:45am UTC](https://discuss.elastic.co/t/filebeat-output-empty-json-array-as-null-instead-of/276604/1 "2021-06-22T04:45:03Z")

</div>

Filebeat output empty JSON array as "null" instead of `[]`.

The original line of JSON is as follows, in which "array\_field" is an empty array.

```auto
{"body": {"array_field": []}}

```

However, after output, the "array\_field" is converted to "null".

```auto
2021-06-22T12:30:21.670+0800 INFO log/harvester.go:302 Harvester started for file: /Users/wangji/example.log
{"array_field":null}

```

I expected the output should be the same as the original input.

Example configuration YAML:

```auto
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /Users/wangji/example.log
  json:
    message_key: json

output.console:
  codec.format.string: '%{[json.body]}'

```

The version of filebeat I tried is :

```auto
filebeat version 7.13.2 (amd64), libbeat 7.13.2 [686ba416a74193f2e69dcfa2eb142f4364a79307 built 2021-06-10 21:04:13 +0000 UTC]

```

I am suspecting that this behavior is a bug, which is caused by this line:

> <https://github.com/elastic/beats/blob/master/libbeat/common/event.go#L134>

When the `v.Len()` equals 0, this method will return a "nil" instead of an empty `interface{}` array.  
Change the line as follows can fix the anomaly behavior. This change will explicitly initialize the return value as an empty array of `interface{}` type.

```auto
sliceValues := []interface{}{}

```

---

<div class="post-metadata">

**Author:** ![ijingo](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ijingo](https://discuss.elastic.co/u/ijingo)\
**Post date:** [June 30, 2021, 7:49am UTC](https://discuss.elastic.co/t/filebeat-output-empty-json-array-as-null-instead-of/276604/2 "2021-06-30T07:49:23Z")

</div>

hello?

---

<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:** [July 28, 2021, 9:49am UTC](https://discuss.elastic.co/t/filebeat-output-empty-json-array-as-null-instead-of/276604/3 "2021-07-28T09:49:31Z")

</div>

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