Is there a way to get Keyword in key is String and not atom?

Background

I have a Keywords list I got from HTTPoison that looks like this:

        [
          {"Date", "Tue, 10 Jan 2023 09:47:09 GMT"},
          {"Content-Type", "text/html; charset=utf-8"},
          {"Transfer-Encoding", "chunked"},
          {"Connection", "keep-alive"},
          {"set-cookie",
           "JWT=some_cookie; Domain=.mywebsite; Expires=Sat, 11-Mar-2023 09:47:09 GMT; Secure; HttpOnly; Path=/; SameSite=Lax"},          {"x-frame-options", "sameorigin"},
          {"strict-transport-security", "max-age=2592000; includeSubDomains; preload"},
          {"CF-Cache-Status", "DYNAMIC"},
          {"X-Content-Type-Options", "nosniff"},
          {"Server", "cloudflare"}
        ]

To me, this looks like a Keyword, however, the keys are Strings and not atoms, thus I cannot use the Keyword.get/3 function nor any of its friends.

Question

What is the Elixir way of getting the a value from this keyword list?

List.keyfind

4 Likes

The definition for an (elixir) keyword list is a list of 2-tuples, where the first element is an atom. So what you got here is not a keyword list and therefore Keyword APIs are not supposed to work for that list. There are however some useful functions in List.key* or in erlangs :proplists.

6 Likes