# Handling a JSON key with a name being an empty string ""

**URL:** <https://discuss.elastic.co/t/handling-a-json-key-with-a-name-being-an-empty-string/316486>\
**Category:** Logstash\
**Created:** [October 13, 2022, 4:49am UTC](https://discuss.elastic.co/t/handling-a-json-key-with-a-name-being-an-empty-string/316486 "2022-10-13T04:49:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geekpete](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geekpete/32/20409_2.png) [@geekpete](https://discuss.elastic.co/u/geekpete)\
**Post date:** [October 13, 2022, 4:49am UTC](https://discuss.elastic.co/t/handling-a-json-key-with-a-name-being-an-empty-string/316486/1 "2022-10-13T04:49:50Z")

</div>

Given a block of JSON like:

```auto
{"":"value1","field2":"value2"}

```

Where the first key has a blank name "" but has a regular looking value of `value1`, you might want to conditionally handle such data to avoid problems once indexing into Elasticsearch where empty field names will fail to parse:

`"error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"field name cannot be an empty string"}}}}}`

With a test Logstash pipeline using http input:

```auto
input {
    http {
        port => 8080
    }
}

```

and a test curl to send the test JSON in:

```auto
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"":"value1","field2":"value2"}' \
  http://localhost:8080

```

if you want to just remove an a key with an empty name at the top level of the JSON, you can remove the field by name, which is `""`, using a Ruby filter.  
This is a no-op if no key with a blank name exists so it does not need to use a conditional guard, just remove it if it exists:

```auto
ruby {
  code => '
    event.remove("")
  '
}

```

If you wanted to keep the blank key's value payload rather than discard it, you can copy it to a new key name like `blank_key` then remove the original with:

```auto
ruby {
  code => '
      testevent = event.get("")
      if testevent
        event.remove("")
        event.set("blank_key",testevent)
      end
  '
}

```

---

<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:** [November 10, 2022, 4:49am UTC](https://discuss.elastic.co/t/handling-a-json-key-with-a-name-being-an-empty-string/316486/2 "2022-11-10T04:49:52Z")

</div>

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