How to parse values of an object into struct
iilyak opened this issue · 0 comments
iilyak commented
I have a JSON in the following format.
{
"person1": {
"name": "name1"
},
"person2": {
"name": "name2"
}
}
defmodule Person do
defstruct [:name]
end
How do I specify as
parameter to parse into Person
struct?
I cannot specify %Person{}
since it would mean different thing:
> Poison.decode!(json, %Person{})
%{"person1" => %{"name" => "name1"}, "person2" => %{"name" => "name2"}}
I know that there is no support for things like as: {String, %Person{}}
. Are there any workarounds?