title: Encoding map to JSON using Poison for use with Slack
body: <p>I'm using Poison to encode a map to JSON that will send it to the Slack API. This is what Poison gives me:</p>
  
  <pre><code>"{\"text\":\"changed readme fad996e98e04fd4a861840d92bdcbbcb1e1ec296\"}"
  </code></pre>
  
  <p>When I put that into JSON lint it says it is valid JSON, but Slack responds "invalid payload".</p>
  
  <p>If I change the JSON to look like this</p>
  
  <pre><code>{"text":"changed readme fad996e98e04fd4a861840d92bdcbbcb1e1ec296"}
  </code></pre>
  
  <p>Then it works. Does anyone know where I'm going wrong with this? Do I need to do extra processing on the encoded JSON or is there some header I need to set?</p>
  
  <p>Here is my controller</p>
  
  <pre><code>def create(conn, opts) do
      message = Message.create_struct(opts)
      response = Slack.Messages.send(message)
  
      case response do
        {:ok, data} -&gt;
          render conn, json: Poison.encode!(data)
        {:error, reason} -&gt;
          render conn, json: reason
      end
  end
  </code></pre>
  
  <p>Here is part of the library for sending the messages</p>
  
  <pre><code>defmodule Slack.Messages do
  
    def format_simple_message(map) do
      text = map.description &lt;&gt; " " &lt;&gt; map.commits
      message = %{text: text}
    end
  
    def post_to_slack(map) do
      Slack.post(:empty, map)
    end
  
    def send(map) do
      map
      |&gt; format_simple_message
      |&gt; post_to_slack
    end
  
  end
  </code></pre>
  
  <p>And my HTTPoison processing</p>
  
  <pre><code>defmodule Slack do
    use HTTPoison.Base
  
    @endpoint "http://url.com"
  
    def process_url() do
      @endpoint
    end
  
    def process_response_body(body) do
      body
      |&gt; Poison.decode! # Turns JSON into map
    end
  
    def process_request_body(body) do
      body
      |&gt; Poison.encode! # Turns map into JSON
    end
  end
  </code></pre>
  
  <p>The part that creates the JSON is in the last block.</p>