Unable to output JSON http messages with new lines

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.

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

This will yield the http message body:

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

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

  • Logstash version: 2.3.3
  • Operating System: Ubuntu 16.04

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

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

I added a filter rule which constructs the message:

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:

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

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 -

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