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

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",, "detail"])
1 Like

very grateful to you :smiley: :+1: :muscle: