poison icon indicating copy to clipboard operation
poison copied to clipboard

Decoding to arbitrary structs

Open leg100 opened this issue 8 years ago • 2 comments

How I would go about decoding JSON into arbitrary structs? e.g.:

Poison.decode!(~s([
  {"type": "giraffe", "args": {"height": 400, "age": 27}},
  {"type": "turtle", "args": {"height": 30, "age": 108}}
]), as: [%type{}???])

Where type is arbitrary but one of a finite number of defined structs, and args are the fields for that struct.

leg100 avatar Mar 20 '17 15:03 leg100

You mean as if the data define the type of struct to be used?

roehst avatar Sep 19 '18 19:09 roehst

This is the way: https://github.com/devinus/poison/pull/207

rauann avatar Apr 25 '22 11:04 rauann