# Handling result in JSON

**URL:** <https://forum.elixirforum.com/t/handling-result-in-json/39187>\
**Category:** Questions\
**Tags:** deployment, json\
**Created:** [April 23, 2021, 10:03pm UTC](https://forum.elixirforum.com/t/handling-result-in-json/39187 "2021-04-23T22:03:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilbertosj](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/48db29/32.png) [@gilbertosj](https://forum.elixirforum.com/u/gilbertosj)\
**Post date:** [April 23, 2021, 10:03pm UTC](https://forum.elixirforum.com/t/handling-result-in-json/39187/1 "2021-04-23T22:03:04Z")

</div>

Could help me with this json?

```elixir
json = 
[
%{
roles: "none",
assignments: [
      %{ 
        assignee: %{
          html_url: "https://test.com",
          id: "111111",
          summary: "Crypto ADA",
        },
        at: "2021-04-22T22:00:42-03:00"
      },
      %{ 
        assignee: %{
          html_url: "https://test.com",
          id: "222222",
          summary: "Crypto WIN",
        },
        at: "2021-04-22T22:00:42-03:00"
      },
      %{ 
        assignee: %{
          html_url: "https://test.com",
          id: "333333",
          summary: "Crypto Elongate",
        },
        at: "2021-04-22T22:00:42-03:00"
      },
      %{ 
        assignee: %{
          html_url: "https://test.com",
          id: "44444",
          summary: "Crypto Safemoon",
        },
        at: "2021-04-22T22:00:42-03:00"
      },
      %{ 
        assignee: %{
          html_url: "https://test.com",
          id: "55555",
          summary: "Crypto BTT",
        },
        at: "2021-04-22T22:00:42-03:00"
      }
    ]
}
]

```

I’m using Enum.map, to do the deal.  
Thus

`Enum.map(json, &%{assignments: &1[:assignments]})`

Currently I need the variable “assignments” to show all the names in a string.  
Staying that way

> &1[:assignments] = “Crypto ADA, Crypto WIN, Crypto Elongate, Crypto Safemoon, Crypto BTT”

My current difficulty and taking the summary field

How should I do this within Enum?

---

<div class="post-metadata">

**Author:** ![cenotaph](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cenotaph](https://forum.elixirforum.com/u/cenotaph)\
**Post date:** [April 23, 2021, 10:12pm UTC](https://forum.elixirforum.com/t/handling-result-in-json/39187/2 "2021-04-23T22:12:23Z")

</div>

> [@gilbertosj](#):
>
> Enum.map(json, &%{assignments: &1[:assignments]})

You could just enumerate on the `json[:assignments]` and do `&1.assignee.summary`

---

<div class="post-metadata">

**Author:** ![gilbertosj](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/48db29/32.png) [@gilbertosj](https://forum.elixirforum.com/u/gilbertosj)\
**Post date:** [April 24, 2021, 2:29am UTC](https://forum.elixirforum.com/t/handling-result-in-json/39187/3 "2021-04-24T02:29:08Z")

</div>

Whenever I try to enter “assignee” it returns an error.

I have tried several ways.

1. 

`Enum.map(incidents, &%{assignments: &1[:assignments][:assignee]})`  
2.  
`Enum.map(incidents, &%{assignments: &1.assignments.assignee})`  
3.  
`Enum.map(incidents, &%{assignments: &1.assignments[:assignee]})`

Error displayed

> \*\* (ArgumentError) you attempted to apply :assignee on [%{assignee: %{html\_url: “https:// …  
> }], :assignee, )  
> (stdlib 3.14) erl\_eval.erl:680: :erl\_eval.do\_apply/6  
> (stdlib 3.14) erl\_eval.erl:786: :erl\_eval.eval\_map\_fields/5  
> (stdlib 3.14) erl\_eval.erl:263: :erl\_eval.expr/5  
> (elixir 1.11.2) lib/enum.ex:1399: Enum.”-map/2-lists^map/1-0-"/2  
> )

---

<div class="post-metadata">

**Author:** ![cenotaph](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cenotaph](https://forum.elixirforum.com/u/cenotaph)\
**Post date:** [April 24, 2021, 2:32am UTC](https://forum.elixirforum.com/t/handling-result-in-json/39187/4 "2021-04-24T02:32:06Z")

</div>

the code you sent previously is different than the second one. if your `json` is `incidents` then it would be

```elixir
Enum.map(incidents.assignments, & &1.assignee.summary)

```

---

<div class="post-metadata">

**Author:** ![gregvaughn](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gregvaughn/32/954_2.png) [@gregvaughn](https://forum.elixirforum.com/u/gregvaughn)\
**Post date:** [April 24, 2021, 5:18pm UTC](https://forum.elixirforum.com/t/handling-result-in-json/39187/5 "2021-04-24T17:18:52Z")

</div>

I would use something like this (assuming the exact `json` structure in the top post)

```elixir
iex(66)> json |> get_in([Access.at(0), :assignments, Access.all(), :assignee, :summary]) |> Enum.join(", ")
"Crypto ADA, Crypto WIN, Crypto Elongate, Crypto Safemoon, Crypto BTT"

```

---

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [April 24, 2021, 8:07pm UTC](https://forum.elixirforum.com/t/handling-result-in-json/39187/6 "2021-04-24T20:07:59Z")

</div>

> [@gilbertosj](#):
>
> Whenever I try to enter “assignee” it returns an error.
> 
> I have tried several ways.
> 
> `Enum.map(incidents, &%{assignments: &1[:assignments][:assignee]})`  
> 2.  
> `Enum.map(incidents, &%{assignments: &1.assignments.assignee})`  
> 3.  
> `Enum.map(incidents, &%{assignments: &1.assignments[:assignee]})`

When writing code like this, you want to carefully consider what shape the data is in at each step:

- start with `Enum.map(incidents, ...)`. So inside the `...`, `&1` will be a single incident - a map
- `&1.assignments` or `&1[:assignments]`: either of these returns a LIST of assignments
- so both `&1.assignments.assignee` and `&1[:assignments].assignee` complain, because a list is not a map
