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

Document how to use nested JSON decoding to structs in more detail #200

Open
DaniruKun opened this issue Oct 10, 2021 · 1 comment
Open

Comments

@DaniruKun
Copy link

At the moment, there is practically no documentation on advanced usage of Poison.decode with the as option for decoding JSON to deeply nested structures with arrays of objects.

This needs at least one advanced example (either in the README or API docs).

@ivan-srsen
Copy link

You need to define model structure, like this:

def from_json(json) when is_binary(json),
do: json |> Poison.decode!(%{as: model_structure(), keys: :atoms})

defp model_structure do
%Model1{
model2: %Model2{
model3: %Model3{}
}
}
end```

It would be cool if it could decode a model based on a typespec.

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

2 participants