I want to parse a string in Elixir. It obviously is binary.
I want to get the value of left_operand, it is '2', but I am not sure how to do it. Because it's like a string, list, tuple mix stuff.
iex(13)> str = "[{\"start_usage\":\"0\",\"left_operand\":\"2\"}]"
iex(15)> is_binary str
true
The string is JSON format retrieved from MySQL.
I want to use the devinus/poison module to parse it, but I'm not sure how to deal with the first and last double quotes (").
It seems that I just need the tuple part so I can do it like
iex(5)> s = Poison.Parser.parse!(~s({\"start_usage\":\"0\",\"left_operand\":\"2\"}))
%{"left_operand" => "2", "start_usage" => "0"}
iex(6)> s["left_operand"]
"2"
But I don't know how to get the tuple part.
Thanks in advance
EDIT:
I think I figured out how to do it my way.
iex> iex(4)> [s] = Poison.Parser.parse!("[{\"start_usage\":\"0\",\"left_operand\":\"2\"}]")
[%{"left_operand" => "2", "start_usage" => "0"}]
iex(5)> s
%{"left_operand" => "2", "start_usage" => "0"}
iex(6)> s["left_operand"]
"2"
I am not sure why this works, I didn't pass the ~s prefix