sahilpaudel

sahilpaudel

Modifying the response array objects

I want to get just the id and name from the object the rest of the data are irrelevant to me.
Can you pleas help me how to go about that.

def call(param) do
    System.get_env("LOCATION_SERVICE_HOST") <> param
      |> HttpClient.get
      |> format_response
end

def format_response({ok, response}) do
    response
 end

The response of call function

[
    {
        "countryCode": "IN",
        "courierApplicable": false,
        "id": 1,
        "isActive": true,
        "name": "",
        "stateId": 5,
        "supplierCityId": 1
    },
    {
        "countryCode": "IN",
        "courierApplicable": false,
        "id": 2,
        "isActive": true,
        "name": "",
        "stateId": 1,
    },
  ...
]

Expected result

[
    {
        "id": 1,
        "name": ""
    },
    {
        "id": 2,
        "name": ""
    },
  ...
]

Most Liked

sahilpaudel

sahilpaudel

|> Enum.map(fn x -> %{id: x.id, name: x.name} end)

This seems to have worked

Last Post!

kokolegorille

kokolegorille

This would have worked too

|> Enum.map(& %{id: &1.id, name: &1.name})

BTW “id” is not equal to id:, but the working code uses :id…

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
New
joeerl
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
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement