I have a Phoenix/Elixir application. And I have a module in the "lib" folder in which I want to parse JSON. If it was in a controller or model, it'd be easier to do. But in the "lib" I don't have access to all those helper modules, do I? Then how can I do that? I need actually parse it in a just struct for which I don't have no model. I've looked into Poison but it seemed to that in order to use it I'd have to have a model in which I'd have to include @derive [Poison.Encoder]
. Whereas I don't have one, I just want to convert a JSON string into a struct, like this:
" "\{"\"\a\": 123, "\b\": 456 "\}"\ " ===> %{a: 123, b: 456}
How can I do that?
update
j_str = "{\"text\":\"changed readme fad996e98e04fd4a861840d92bdcbbcb1e1ec296\", \"user_name\":\"name123\"}"
Poison.Parser.parse!(~s(j_str)) # => ** (Poison.SyntaxError) Unexpected token at position 0: j
# or
Poison.decode!(~s|j_str|) # the same error