# Protocol String.Chars not implemented for

**URL:** <https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511>\
**Category:** Questions\
**Tags:** protocols, troubleshooting\
**Created:** [May 4, 2016, 4:58am UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511 "2016-05-04T04:58:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriki](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@sriki](https://forum.elixirforum.com/u/sriki)\
**Post date:** [May 4, 2016, 4:58am UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/1 "2016-05-04T04:58:56Z")

</div>

I got the error mentioned in the title while running the following code. The weird part is I did get the response I expected but with this message attached.

```
defmodule Kodi.Worker do
def get_response() do
    result = url_for() |> HTTPoison.get |> parse_response
    case result do
        {:ok, response} -> "response: #{response}"
        :error -> "query error"
    end
end

defp url_for() do
    "http://192.168.0.104:8080/jsonrpc?request={%22jsonrpc%22:%20%222.0%22,%20%22id%22:%201,%20%22method%22:%20%22Playlist.GetPlaylists%22}"
end

defp parse_response({:ok, %HTTPoison.Response{body: body, status_code: 200}}) do
    body |> JSON.decode! |> filter_response
end

defp parse_response(_) do
    :error
end

defp filter_response(json) do
    try do
        #response = (json["result"])
        #{:ok, response}
        {:ok, json}
    rescue
        _ -> :error
    end
end
end

```

Any idea?

EDIT:  
Error message:  
\*\* (Protocol.UndefinedError) protocol String.Chars not implemented for %HTTPoison.Response{body: “{"id":1,"jsonrpc":"2.0","result":[{"playlistid":0,"type":"audio"},{"playlistid":1,"type":"video"},{"playlistid":2,"type":"picture"}]}”, headers: [{“Content-Length”, “133”}, {“Content-Type”, “application/json”}, {“Date”, “Wed, 04 May 2016 05:00:55 GMT”}], status\_code: 200}  
(elixir) lib/string/chars.ex:3: String.Chars.impl\_for!/1  
(elixir) lib/string/chars.ex:17: String.Chars.to\_string/1  
(kodi) lib/worker.ex:5: Kodi.Worker.get\_response/0

It looks like you are correct. I might be treating the response as string when it’s not. I will look into it again to figure out how to fix it. Thanks.

I made a mistake in my code. I am fixing it and update the thread “soon”.

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [May 4, 2016, 5:23am UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/2 "2016-05-04T05:23:17Z")

</div>

It would have been much easier if you had posted the full errormessage including the module for that `String.Chars` is not implemented and the line number it is complaining about.

So I have to guess for now where the message does come from, and the sole possbility I do see for now is this line: `{:ok, response} -> "response: #{response}"`. `response` is of type `HTTPotion.Response` or `HTTPotion..AsyncResponse` and after a quick look up in the sources I wasn’t able to find a `defimpl` for both of them and they don’t seem to have `Inspect` implemented either (there was not a single `defimpl` in the repository according to github search).

So If that is really the line causing you trouble, You need to get the information you want to have in the string in another way.

---

<div class="post-metadata">

**Author:** ![hubertlepicki](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hubertlepicki/32/6822_2.png) [@hubertlepicki](https://forum.elixirforum.com/u/hubertlepicki)\
**Post date:** [May 4, 2016, 5:28am UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/3 "2016-05-04T05:28:17Z")

</div>

You are _not_ getting this error caused by the code above.

What may be happening is that you are getting a JSON response out from the get\_response() function, and later on treat it as a string, while it is Map.

I usually get this error message when I try to use `IO.puts` instead of `IO.inspect` to print something out to console that is not a string.

Fuller code example would be better, along with full error message (you cut it off in most interesting part, before the module name).

---

<div class="post-metadata">

**Author:** ![sriki](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@sriki](https://forum.elixirforum.com/u/sriki)\
**Post date:** [May 4, 2016, 6:25am UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/4 "2016-05-04T06:25:37Z")

</div>

> [@sriki](#):
>
> body |\> JSON.decode! |\> filter\_response

I missed the “!” in the above line. With that added, I still got an error message but it’s more about the json data structure and how it’s being parsed. I will deal with it. Thanks for pointing in the right direction and apologies for cutting off the full error message.

---

<div class="post-metadata">

**Author:** ![raichuk](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/raichuk/32/1162_2.png) [@raichuk](https://forum.elixirforum.com/u/raichuk)\
**Post date:** [May 4, 2016, 3:10pm UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/5 "2016-05-04T15:10:56Z")

</div>

> [@sriki](#):
>
> {:ok, response} -\> “response: #{response}”

I think that the proble is that you need to use inspect, like this:  
`{:ok, response} -&gt; "response: #{ inspectresponse}"`

---

<div class="post-metadata">

**Author:** ![guljarpd](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/guljarpd/32/10963_2.png) [@guljarpd](https://forum.elixirforum.com/u/guljarpd)\
**Post date:** [July 19, 2018, 5:43am UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/6 "2018-07-19T05:43:51Z")

</div>

#hubertlepicki  
Thanks,  
Your post saved my lot of time, same issue I was also facing.

---

<div class="post-metadata">

**Author:** ![pixare40](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pixare40/32/10774_2.png) [@pixare40](https://forum.elixirforum.com/u/pixare40)\
**Post date:** [August 3, 2020, 12:12am UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/7 "2020-08-03T00:12:11Z")

</div>

This saved me as well. Thi was my exact issue

---

<div class="post-metadata">

**Author:** ![karan](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/k/58f4c7/32.png) [@karan](https://forum.elixirforum.com/u/karan)\
**Post date:** [October 21, 2021, 12:11pm UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/8 "2021-10-21T12:11:49Z")

</div>

mine too

---

<div class="post-metadata">

**Author:** ![zoom6x](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/z/cab0a1/32.png) [@zoom6x](https://forum.elixirforum.com/u/zoom6x)\
**Post date:** [October 30, 2023, 6:38pm UTC](https://forum.elixirforum.com/t/protocol-string-chars-not-implemented-for/511/9 "2023-10-30T18:38:46Z")

</div>

thanks a lot. it worked perfectly
