jonoke
Poison error on attempting to serialize a map
At a first attempt to serialize a map, I tried using Poision but I get an error … I assumed Poison could handle all data types … it doesn’t seem to like the tuple of tuples.
This shows the error … the {mtime: {{2019, 3, 16}, {23, 47, 17}}} was the entry in my larger map Poison didn’t like. When I take the :mtime item out of the map it works as expected.
Any help appreciated.
iex(1)> {:ok, %{mtime: mtime}} = File.stat("test.json")
{:ok,
%File.Stat{
access: :read_write,
atime: {{2019, 3, 16}, {23, 47, 33}},
ctime: {{2019, 3, 16}, {23, 47, 17}},
gid: 1000,
inode: 12189812,
links: 1,
major_device: 2053,
minor_device: 0,
mode: 33188,
mtime: {{2019, 3, 16}, {23, 47, 17}},
size: 245,
type: :regular,
uid: 1000
}}
iex(2)> mtime
{{2019, 3, 16}, {23, 47, 17}}
iex(3)> y = Poison.encode(mtime)
{:error, {:invalid, {{2019, 3, 16}, {23, 47, 17}}}}
iex(4)>
Jonathan.
Most Liked
dimitarvp
JSON has no concept of tuples. Only JS arrays (Elixir lists).
So you’ll have to convert your data structures to be JSON-friendly.
3
blatyo
Conduit Core Team
It’s worth noting that if you have a DateTime instead, Poison will know how to JSONify that into an ISO 8601 string. Just note that on the decode side, you’ll get a string and have to convert it back to a DateTime yourself.
1
Popular in Questions
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
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
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
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
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
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
Other popular topics
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
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
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
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
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
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
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
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








