mxst
Use Poison to decode map of structs
Hey everyone,
I was wondering if there is a chance to decode am map from json to a map of predefined structs. Important is that the keys are not predefined.
So in the end I would love to transform this
{
"text": "A pet food distribution center where the animal can tap the screen and receive a treat or meal. Would allow for healthy regulation and training.",
"annotation_candidates": {
"tap": {
"text": "tap",
"resource_candidates": [
{
"label": "Tap water",
"resource": "http://dbpedia.org/resource/Tap_water"
},
{
"label": "Tap dance",
"resource": "http://dbpedia.org/resource/Tap_dance"
}
]
},
"receive": {
"name": "receive",
"offset": 71,
"resource_candidates": [
{
"label": "Radio receiver",
"resource": "http://dbpedia.org/resource/Radio_receiver"
}
]
}
]
}
into this
%AnnotationCandidates{
text: "A pet food distribution center where the animal can tap the screen and receive a treat or meal. Would allow for healthy regulation and training.",
annotation_candidates: %{
"tap" => %AnnotationCandidate{
text: "tap",
offset: 52,
resource_candidates: [
%ResourceCandidate{
label: "Tap Water"
resource: "http://dbpedia.org/resource/Tap_water",
confidence: 0.2600142258675502
},
%ResourceCandidate{ ... }
]
},
"receive" => %AnnotationCandidate{ ... }
}
}
I don’t know if that is possible (or a dumb idea)
Thank you for your help.
Most Liked
Fl4m3Ph03n1x
axelson
Scenic Core Team
Structs have fixed keys. So if you don’t know the keys ahead of time then you can’t use a structural and need to use a map instead.
1
Popular in Questions
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
I would like to know what is the best IDE for elixir development?
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Other popular topics
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New







