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 want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
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
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
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
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
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
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
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
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
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








