# Explanation of string interpolation?

**URL:** <https://discuss.elastic.co/t/explanation-of-string-interpolation/126275>\
**Category:** Logstash\
**Created:** [March 30, 2018, 7:27pm UTC](https://discuss.elastic.co/t/explanation-of-string-interpolation/126275 "2018-03-30T19:27:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shannon\_Carey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shannon_carey/32/29417_2.png) [@Shannon\_Carey](https://discuss.elastic.co/u/Shannon_Carey)\
**Post date:** [March 30, 2018, 7:27pm UTC](https://discuss.elastic.co/t/explanation-of-string-interpolation/126275/1 "2018-03-30T19:27:51Z")

</div>

I cannot find where in the docs it explains how string interpolation with `%{myvar}` works... Is there an explanation?

I have an "http" output which uses the "mapping" config to control the structure of the output like so:

```auto
...
output {
    http {
      keepalive => false
      retry_non_idempotent => true
      automatic_retries => 3
      request_timeout => 10
      socket_timeout => 10
      format => "json"
      http_method => "post"
      url => "https://example.com/data.json"
      content_type => "application/json"
      mapping => { "foo" => "%{foo}"
        "bar" => "%{bar}" }
    }
}

```

If I have a "foo" in the event, then it works properly. However, if I do not have a "foo", then in my ouput it get the literal string "%{foo}". That's definitely not what I want... it should be a blank string.

Is that expected behavior?

If so, is there a way to populate a default value for something that's missing?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 30, 2018, 8:00pm UTC](https://discuss.elastic.co/t/explanation-of-string-interpolation/126275/2 "2018-03-30T20:00:01Z")

</div>

> I cannot find where in the docs it explains how string interpolation with %{myvar} works... Is there an explanation?

> **[Accessing event data and fields | Logstash Reference \[8.11\] | Elastic](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#sprintf)**

> If I have a "foo" in the event, then it works properly. However, if I do not have a "foo", then in my ouput it get the literal string "%{foo}". That's definitely not what I want... it should be a blank string.
> 
> Is that expected behavior?

Yes. See [Default value for sprintf interpolation (Feature) · Issue #4416 · elastic/logstash · GitHub](https://github.com/elastic/logstash/issues/4416) for a feature request.

> If so, is there a way to populate a default value for something that's missing?

There's an example in the GitHub issue above.

---

<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 27, 2018, 8:00pm UTC](https://discuss.elastic.co/t/explanation-of-string-interpolation/126275/3 "2018-04-27T20:00:12Z")

</div>

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