# Unable to output JSON http messages with new lines

**URL:** <https://discuss.elastic.co/t/unable-to-output-json-http-messages-with-new-lines/55291>\
**Category:** Logstash\
**Created:** [July 12, 2016, 11:43am UTC](https://discuss.elastic.co/t/unable-to-output-json-http-messages-with-new-lines/55291 "2016-07-12T11:43:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raffaele](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@raffaele](https://discuss.elastic.co/u/raffaele)\
**Post date:** [July 12, 2016, 11:43am UTC](https://discuss.elastic.co/t/unable-to-output-json-http-messages-with-new-lines/55291/1 "2016-07-12T11:43:10Z")

</div>

Hi there

I am struggling getting Logstash to insert new lines in JSON http output messages. Configuring Logstash to send out http messages (output-http plugin) works however, putting a new line into the mapping text will end up with the new line being escaped. I am unsure about how to get Logstash to leave the new line as it is.

```auto
http {
  http_method => post
  url => "http://..."
  format => json
  mapping => {
    somefield => "Some text\nSome more text..."
  }
}

```

This will yield the http message body:

```auto
{"somefield": "Some text\\nSome more text"}

```

Note: The `\n` got escaped to `\\n`.

- Logstash version: 2.3.3
- Operating System: Ubuntu 16.04

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [August 29, 2016, 4:41pm UTC](https://discuss.elastic.co/t/unable-to-output-json-http-messages-with-new-lines/55291/2 "2016-08-29T16:41:13Z")

</div>

Hi @raffaele

Did you got any solution for this?  
I know this is very old post, but i am also struggling from past few days and not getting any response from community

---

<div class="post-metadata">

**Author:** ![raffaele](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@raffaele](https://discuss.elastic.co/u/raffaele)\
**Post date:** [August 30, 2016, 5:41am UTC](https://discuss.elastic.co/t/unable-to-output-json-http-messages-with-new-lines/55291/3 "2016-08-30T05:41:37Z")

</div>

Yes I was able to solve this issue with a hack.

I added a filter rule which constructs the message:

```auto
mutate {
  add_field => {"[@metadata][my_message]" => "Some\nMessage"}
}
# There does not seem to be a way to have new lines in Logstash variables
# therefore, we apply a hack here.
ruby {
  code => "event['@metadata']['my_message'].gsub!('\n', 10.chr)"
}

```

As you can see I make use of a ruby filter to search for new line escape character sequences and replace that sequence with an actual newline character.

I can use this message in output rules:

```auto
http {
  http_method => post
    url => "https://..."
  format => json
  mapping => {
    somefield => "%{[@metadata][my_message]}"
  }
}

```

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [August 30, 2016, 6:05am UTC](https://discuss.elastic.co/t/unable-to-output-json-http-messages-with-new-lines/55291/4 "2016-08-30T06:05:07Z")

</div>

Hi I am trying same stuff with "message" format as i am dealing with SOAP request

How i can use this below headers with html output. I am using header=\> command but not sure how exactly i can place them

I have end point URL like this -

> **[.xyz Domain Names | Join Generation XYZ](https://gen.xyz/)**
>
> .xyz is for every website, everywhere.™ We offer the most flexible and affordable domain names to create choice for the next generation of internet users.

This below headers i got from SOAP UI, i am able post the request through SOAP request

```
POST https://xyz.com:443/acnuserService/userService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://xmlns.xyz.com/apps/abc/sdfg/user/userService/createuser"
Content-Length: 625
Host: xyz.com:443
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic a2V2aW4uc2Nob3R0OlhEQzg4NTk0
```

---

<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 6, 2017, 4:40am UTC](https://discuss.elastic.co/t/unable-to-output-json-http-messages-with-new-lines/55291/5 "2017-07-06T04:40:57Z")

</div>


