Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to parse values of an object into struct #188

Open
iilyak opened this issue May 29, 2019 · 0 comments
Open

How to parse values of an object into struct #188

iilyak opened this issue May 29, 2019 · 0 comments

Comments

@iilyak
Copy link

iilyak commented May 29, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant