Below is the json I get after encoding it using Jason
"{\"topic\": \"dummy_topic\", \"msg\": \"{\"fruit\":\"apple\",\"dish\":\"apple-pie\"}\"}"
I am trying to pass it as the body of the request while calling an API using HTTPoison , it gives me the json decode error
tried the same on terminal and I get below ,
iex(10)> var = "{\"topic\": \"dummy_topic\", \"msg\": \"{\"fruit\":\"apple\",\"dish\":\"apple-pie\"}\"}"
"{\"topic\": \"dummy_topic\", \"msg\": \"{\"fruit\":\"apple\",\"dish\":\"apple-pie\"}\"}"
iex(11)> Jason.decode(var)
{:error,
%Jason.DecodeError{
data: "{\"topic\": \"dummy_topic\", \"msg\": \"{\"fruit\":\"apple\",\"dish\":\"apple-pie\"}\"}",
position: 35,
token: nil
}}
Which is the exact same error I get when when I use HTTPoison ,
my expectation is I should be getting something like below when I use Jason.decode ,
%{
"topic" => "dummy_topic",
"msg" => %{"fruit" => "apple", "dish" => "apple-pie"}
}
Do you know where I am getting it wrong or what can be done to get the expected output ?






















