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
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
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 there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when 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
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
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
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
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
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
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
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
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
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







