Jason decoding escaped backslash issue?

Given this setup (note the escaped backslash):

encoded = "\"foo\\bar.baz\""
decoded = Jason.decode!(encoded)

The result is:
IO.puts(decoded) -> foo^Har.baz

Shouldn’t decoded look like this instead?
IO.puts(decoded) -> foo\bar.baz

Thanks.

iex(2)> "\"foo\\bar.baz\""
"\"foo\\bar.baz\""
iex(3)> IO.puts "\"foo\\bar.baz\""
"foo\bar.baz"
:ok
iex(4)> IO.puts "\b"
^H

The string you’re creating has \b in it.

2 Likes