walkersorlie
Decode JSON Nested Objects
I’ll preface that I am very new to Elixir. I am trying to decode a paginated JSON response from my API but I am a bit lost on exactly how to implement the decoding.
This is what the top-level JSON response looks like:
_embedded:
collection_currently:
0: {...}
1: {...}
2: {...}
...
_links:
first: {...}
self: {...}
...
page:
size: 4
totalElemnts: 28
totalPages: 7
number: 7
I’ve successfully decoded a single collection_currently object using the code from the Poison README. My question now is how exactly do I go about decoding this whole response? I’ve looked at this question which is close to what I’m trying to do, but as I said I’m new to Elixir and don’t fully understand the answer.
Any help would be appreciated! Thanks.
Most Liked
NobbZ
Last Post!
drew.gulino
You can use :jsn.as_map/1 (jsn | Hex)
~s(
{
"fields": {
"summary": "Bug!",
"issuetype": {
"id": "10005"
},
"project": {
"key": "BUG"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Description - Bug Found",
"type": "text"
}
]
}
]
}
}
}
)
|> Jason.decode!
|> :jsn.as_map
end
%{
"fields" => %{
"description" => %{
"content" => [
%{
"content" => [
%{"text" => "Description - Bug Found", "type" => "text"}
],
"type" => "paragraph"
}
],
"type" => "doc",
"version" => 1
},
"issuetype" => %{"id" => "10005"},
"project" => %{"key" => "BUG"},
"summary" => "Bug!"
}
}
0
Popular in Questions
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 the...
New
I would like to know what is the best IDE for elixir development?
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
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
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
Other popular topics
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
I would like to know what is the best IDE for elixir development?
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









