Maxximiliann

Maxximiliann

Poison.decode! - (MatchError) no match of right hand side value

(Please note: Exlir/Poison Experience Level: Beginner so please Eli5)

Given:

iex(1)> results = HTTPoison.get!("https://nodes.wavesnodes.com/assets/balance/3PDh3tDWWXmJtfoqRkf1p9PnZAHmBLcWXFW")
%HTTPoison.Response{
  body: "{\"address\":\"3PDh3tDWWXmJtfoqRkf1p9PnZAHmBLcWXFW\",\"balances\":[{\"assetId\":\"6GQkwHGyd769EghKQ6qXhAHG55JyaFjK7VGWEKSSg4Z8\",\"balance\":100000000,\"reissuable\":false,\"minSponsoredAssetFee\":null,\"sponsorBalance\":null,\"quantity\":2099443248805633,\"issueTransaction\":{\"senderPublicKey\":\"2TW1p199hYspTxt3hZc2wm9VGGDE4qFxyY2Th1HoFVww\",\"quantity\":2100000000000000,\"fee\":100000000,\"description\":\"\\\"Progression\\\" conception intelligente de jeton innovant qui se limite à évaluer 0,0001 de vagues par jour, les commandes sont limitées à 100 minutes pour stimuler la progression quotidienne.\\n\\\"Progression\\\" innovative token intelligent design that is limited to valuing 0.0001 of waves per day, orders are limited to 100 minutes to stimulate daily progression.\",\"type\":3,\"version\":2,\"reissuable\":false,\"script\":\"base64:AQQAAAALc3RhcnRIZWlnaHQAAAAAAAAVWMoEAAAACnN0YXJ0UHJpY2UAAAAAAAAAJxAEAAAACGludGVydmFsCQAAaAAAAAIAAAAAAAAAABgAAAAAAAAAADwEAAAAA2V4cAkAAGgAAAACCQAAaAAAAAIAAAAAAAAAAGQAAAAAAAAAADwAAAAAAAAAA+gEAAAAByRtYXRjaDAFAAAAAnR4AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABNFeGNoYW5nZVRyYW5zYWN0aW9uBAAAAAFlBQAAAAckbWF0Y2gwBAAAAARkYXlzCQAAaQAAAAIJAABlAAAAAgUAAAAGaGVpZ2h0BQAAAAtzdGFydEhlaWdodAUAAAAIaW50ZXJ2YWwDAwMJAABnAAAAAggFAAAAAWUAAAAFcHJpY2UJAABoAAAAAgUAAAAKc3RhcnRQcmljZQkAAGQAAAACAAAAAAAAAAABCQAAaAAAAAIFAAAABGRheXMFAAAABGRheXMJAQAAAAEhAAAAAQkBAAAACWlzRGVmaW5lZAAAAAEICAgFAAAAAWUAAAAJc2VsbE9yZGVyAAAACWFzc2V0UGFpcgAAAApwcmljZUFzc2V0BwkAAGcAAAACBQAAAANleHAJAABlAAAAAggIBQAAAAFlAAAACXNlbGxPcmRlcgAAAApleHBpcmF0aW9uCAgFAAAAAWUAAAAJc2VsbE9yZGVyAAAACXRpbWVzdGFtcAcJAABnAAAAAgUAAAADZXhwCQAAZQAAAAIICAUAAAABZQAAAAhidXlPcmRlcgAAAApleHBpcmF0aW9uCAgFAAAAAWUAAAAIYnV5T3JkZXIAAAAJdGltZXN0YW1wBwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAPQnVyblRyYW5zYWN0aW9uBAAAAAJ0eAUAAAAHJG1hdGNoMAYGF8/Q+A==\",\"sender\":\"3PMQ27yBjrshdxGmFjTZHY6taN17saQyfM8\",\"feeAssetId\":null,\"chainId\":87,\"proofs\":[\"2YAgh7QQ49oFqgTfDYT5mh58xcqspR2kQJrpiLYRTtyPrtakUuYjVyt9ejr5m3suF7FZUhze1ZmXU1Ry6yJdWheV\"],\"assetId\":\"6GQkwHGyd769EghKQ6qXhAHG55JyaFjK7VGWEKSSg4Z8\",\"decimals\":8,\"name\":\"Progression\",\"id\":\"6GQkwHGyd769EghKQ6qXhAHG55JyaFjK7VGWEKSSg4Z8\",\"timestamp\":1550319832173}},{\"assetId\":\"51LxAtwBXapvvTFSbbh4nLyWFxH6x8ocfNvrXxbTChze\",\"balance\":6,\"reissuable\":false,\"minSponsoredAssetFee\":10000,\"sponsorBalance\":90323001,\"quantity\":9999999886689962,\"issueTransaction\":{\"senderPublicKey\":\"FCfKDQiCaNruTAj984WCrQLHS1j1c8Fv5JzgKswgAhoy\",\"quantity\":10000000000000000,\"fee\":100000000,\"description\":\"TOR Corporation\\nОфициальная чат-группа монет TOR https://t.me/projecttorcoin \\nWhite paper https://docs.google.com/document/d/1LJfo6X82cAjLI4tahkVN-jR_GU8a4d2aZ_tFtXP4yYI/edit?usp=sharing Дорожная карта https://docs.google.com/document/d/1qBheIvDO3KSfyQnWQdbwUBKZtalaILhCak03fJlQRTk/edit?usp=sharing\",\"type\":3,\"version\":2,\"reissuable\":false,\"script\":null,\"sender\":\"3P287ZEpVU14SAr4jhCF58fZPzfkQv4LXqm\",\"feeAssetId\":null,\"chainId\":87,\"proofs\":[\"4f7ZzQ5ZgZskxnCDhU4RKx6MWCHNVrnJs8hKRfGWX35aSyJtcJqrQuUaahrqcAnYU8dpDq8rRUvTtwa6VhcEEx7v\"],\"assetId\":\"51LxAtwBXapvvTFSbbh4nLyWFxH6x8ocfNvrXxbTChze\",\"decimals\":6,\"name\":\"TORCorp\",\"id\":\"51LxAtwBXapvvTFSbbh4nLyWFxH6x8ocfNvrXxbTChze\",\"timestamp\":1541398865252}},{\"assetId\":\"GAAZu8fsWfrZBFgweMMAFEcjrW9CFRxPEqmGcbSGWVDF\",\"balance\":300000000,\"reissuable\":false,\"minSponsoredAssetFee\":null,\"sponsorBalance\":null,\"quantity\":4999999200000000,\"issueTransaction\":{\"senderPublicKey\":\"jYTtcsLgDD5NcoDHUAnHLdC9PjeSwyjxFysptotgHjq\",\"quantity\":10000000000000000,\"fee\":100000000,\"description\":\"K975 Token\",\"type\":3,\"version\":2,\"reissuable\":false,\"script\":null,\"sender\":\"3PMSXKE9AqLMw2Yh5nTscm2DSJP677hf2QJ\",\"feeAssetId\":null,\"chainId\":87,\"proofs\":[\"2GPLuTFZFb8bLKV1AJ15VUtjHpmMcvXo8nNmi9F5pwdptgudiGXwU2efM5BFCP2FvK7zAdR5zQPBguJFY4kyUqXd\"],\"assetId\":\"GAAZu8fsWfrZBFgweMMAFEcjrW9CFRxPEqmGcbSGWVDF\",\"decimals\":8,\"name\":\"K975\",\"id\":\"GAAZu8fsWfrZBFgweMMAFEcjrW9CFRxPEqmGcbSGWVDF\",\"timestamp\":1568118516242}},{\"assetId\":\"2rdZt8RxEftbmz34HLBd7Au2icyScgAe5YoipeT7GwK2\",\"balance\":1,\"reissuable\":false,\"minSponsoredAssetFee\":null,\"sponsorBalance\":null,\"quantity\":49999986,\"issueTransaction\":{\"senderPublicKey\":\"StYAY98BDsSDvhMRFauKxn5pWEcD6KxnRnvPDbtceZ" <> ...,
  headers: [
    {"Date", "Sat, 12 Oct 2019 20:01:32 GMT"},
    {"Content-Type", "application/json"}, 
    {"Transfer-Encoding", "chunked"},
    {"Connection", "keep-alive"},
    {"Set-Cookie",
     "__cfduid=d7522b5d559f3952392299b4e3c07a2cb1570910492; expires=Sun, 11-Oct-20 20:01:32 GMT; path=/; domain=.wavesnodes.com; HttpOnly"}, 
    {"Vary", "Accept-Encoding"},
    {"Access-Control-Allow-Origin", "*"},
    {"Access-Control-Allow-Credentials", "true"},
    {"Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE"},
    {"Access-Control-Allow-Headers",
     "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,signature,timestamp"},
    {"Access-Control-Expose-Headers", "Content-Length,Content-Range"},
    {"Backend", "ca-2"},
    {"Content-Security-Policy",
     "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' online.swagger.io"},
    {"X-Frame-Options", "DENY"},
    {"X-XSS-Protection", "0"},
    {"X-Content-Type-Options", "nosniff"},
    {"Referrer-Policy", "unsafe-url"},
    {"CF-Cache-Status", "DYNAMIC"},
    {"Set-Cookie",
     "AWSALB=3/o7aRqBwecPhGPjflqgWoA5R8nviB4AuiJ+hzmjke8QIkv4rXRCeAGXxGHYs4OTYS+C/EfEUc83sWOSdFdpDe7ugPrSkX3GqeX4+BBNCnpy510HP/sehtLLBkim; Expires=Sat, 19 Oct 2019 20:01:32 GMT; Path=/"},
    {"Set-Cookie",
     "__cflb=3256034178; path=/; expires=Sun, 13-Oct-19 19:01:32 GMT; HttpOnly"},
    {"Expect-CT",
     "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""},
    {"Server", "cloudflare"},
    {"CF-RAY", "524baa8f68e9c7c5-DEN"}
  ],
  request: %HTTPoison.Request{
    body: "",
    headers: [], 
    method: :get,
    options: [],
    params: %{},
    url: "https://nodes.wavesnodes.com/assets/balance/3PDh3tDWWXmJtfoqRkf1p9PnZAHmBLcWXFW"
  },
  request_url: "https://nodes.wavesnodes.com/assets/balance/3PDh3tDWWXmJtfoqRkf1p9PnZAHmBLcWXFW",
  status_code: 200
}

Why does this fail?

iex(2)> %{data: items} = Poison.decode!(results.body, keys: :atoms)
** (MatchError) no match of right hand side value: %{address: "3PDh3tDWWXmJtfoqRkf1p9PnZAHmBLcWXFW", balances: [%{assetId: "6GQkwHGyd769EghKQ6qXhAHG55JyaFjK7VGWEKSSg4Z8", balance: 100000000, issueTransaction: %{assetId: "6GQkwHGyd769EghKQ6qXhAHG55JyaFjK7VGWEKSSg4Z8", chainId: 87, decimals: 8, description: "\"Progression\" conception intelligente de jeton innovant qui se limite à évaluer 0,0001 de vagues par jour, les commandes sont limitées à 100 minutes pour stimuler la progression quotidienne.\n\"Progression\" innovative token intelligent design that is limited to valuing 0.0001 of waves per day, orders are limited to 100 minutes to stimulate daily progression.", fee: 100000000, feeAssetId: nil, id: "6GQkwHGyd769EghKQ6qXhAHG55JyaFjK7VGWEKSSg4Z8", name: "Progression", proofs: ["2YAgh7QQ49oFqgTfDYT5mh58xcqspR2kQJrpiLYRTtyPrtakUuYjVyt9ejr5m3suF7FZUhze1ZmXU1Ry6yJdWheV"], quantity: 2100000000000000, reissuable: false, script: "base64:AQQAAAALc3RhcnRIZWlnaHQAAAAAAAAVWMoEAAAACnN0YXJ0UHJpY2UAAAAAAAAAJxAEAAAACGludGVydmFsCQAAaAAAAAIAAAAAAAAAABgAAAAAAAAAADwEAAAAA2V4cAkAAGgAAAACCQAAaAAAAAIAAAAAAAAAAGQAAAAAAAAAADwAAAAAAAAAA+gEAAAAByRtYXRjaDAFAAAAAnR4AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABNFeGNoYW5nZVRyYW5zYWN0aW9uBAAAAAFlBQAAAAckbWF0Y2gwBAAAAARkYXlzCQAAaQAAAAIJAABlAAAAAgUAAAAGaGVpZ2h0BQAAAAtzdGFydEhlaWdodAUAAAAIaW50ZXJ2YWwDAwMJAABnAAAAAggFAAAAAWUAAAAFcHJpY2UJAABoAAAAAgUAAAAKc3RhcnRQcmljZQkAAGQAAAACAAAAAAAAAAABCQAAaAAAAAIFAAAABGRheXMFAAAABGRheXMJAQAAAAEhAAAAAQkBAAAACWlzRGVmaW5lZAAAAAEICAgFAAAAAWUAAAAJc2VsbE9yZGVyAAAACWFzc2V0UGFpcgAAAApwcmljZUFzc2V0BwkAAGcAAAACBQAAAANleHAJAABlAAAAAggIBQAAAAFlAAAACXNlbGxPcmRlcgAAAApleHBpcmF0aW9uCAgFAAAAAWUAAAAJc2VsbE9yZGVyAAAACXRpbWVzdGFtcAcJAABnAAAAAgUAAAADZXhwCQAAZQAAAAIICAUAAAABZQAAAAhidXlPcmRlcgAAAApleHBpcmF0aW9uCAgFAAAAAWUAAAAIYnV5T3JkZXIAAAAJdGltZXN0YW1wBwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAPQnVyblRyYW5zYWN0aW9uBAAAAAJ0eAUAAAAHJG1hdGNoMAYGF8/Q+A==", sender: "3PMQ27yBjrshdxGmFjTZHY6taN17saQyfM8", senderPublicKey: "2TW1p199hYspTxt3hZc2wm9VGGDE4qFxyY2Th1HoFVww", timestamp: 1550319832173, type: 3, version: 2}, minSponsoredAssetFee: nil, quantity: 2099443248805633, reissuable: false, sponsorBalance: nil}, }
    (stdlib) erl_eval.erl:453: :erl_eval.expr/5
    (iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5
    (iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3
    (iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3
    (iex) lib/iex/evaluator.ex:103: IEx.Evaluator.loop/1
    (iex) lib/iex/evaluator.ex:27: IEx.Evaluator.init/4

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Look at the output of Poison.decode!(results.body, keys: :atoms). There isn’t a data key. You’re asserting via %{data: items} that the result of Poison.decode! will be a map with an :data key and then data. The JSON does not have any such key.

Also Liked

Maxximiliann

Maxximiliann

Thanks!

Got it working with:
iex(1)> %{balances: items} = Poison.decode!(results.body, keys: :atoms)

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
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
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
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
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement