eduarRM12

eduarRM12

Trying to access a key within a map list

Hi, I’m new to elixir.

Currently I find myself needing to access a value but due to ignorance I have not been able to, the structure I have is the following and the value I want to access is “detail” => "Error desconocido, I appreciate your collaboration, thank.

%{
    "data" => nil,
    "errors" => [%{
            "code" => "ER404-NN",
            "detail" => "Error desconocido",
            "id" => "9eae1b20-56f5-11ed-859c-0250f209cfd1",
            "status" => 400,
            "title" => "Operación fallida"
        }
    ],
    "message" => nil,
    "meta" => %{
        "clientRequest" => "",
        "messageId" => "",
        "requestDate" => "28/10/2022 14:20:44:748000",
        "responseSize" => 1
    }
}

Marked As Solved

gregvaughn

gregvaughn

I hope you see the main idea here. You want to Map.get the value for the key “errors”. Then you want the List.first element of that. Then you want to Map.get the “detail” key from there. As someone new to Elixir you should be able to write those 3 lines and succeed in your goal.

If you’re looking for something more advanced then what I would use is Kernel.get_in which gives you a shorter syntax for those 3 steps I mentioned above, but still, you need to understand the 3 steps.

get_in(my_structure, ["errors", Access.at(0), "detail"])

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
jerry
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
Jim
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
lk-geimfari
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
alice
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
vonH
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement