What is the cleanest way to generate the following Json string?
{“text”:“hello \n world!”}
There should not be any escaping (" or \n). We need this for Slack integration and it doesn’t allow escaping save for & < >
What is the cleanest way to generate the following Json string?
{“text”:“hello \n world!”}
There should not be any escaping (" or \n). We need this for Slack integration and it doesn’t allow escaping save for & < >
Poison.encode! %{"text": "hello \nworld!"}
?
The result {“text”:“hello \nworld!”} contains the escape characters. If you Try It in the Slack link mentioned, you get Here’s what went wrong: expecting String, }, got undefined
@vishal-h, output in the ‘iex’ shell for example will always be escaped. The actual string you get is correct, though, as you’ll see if you try to print it:
iex(6)> Poison.encode!(%{"text": "hello \nworld!"}) |> IO.puts
{"text":"hello \nworld!"}
:ok
…and then paste the printed output into the Try It tool, eg:
{"text":"hello \nworld!"}
Aah! Right on the money. Thank you!
oh yes, I am sorry, I wasn’t clear enough with my example