Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Allow options to JSON decoder

14 views
Skip to first unread message

Søren Hilmer

unread,
Oct 21, 2024, 7:26:05 AM10/21/24
to elixir-ecto
Hi
I am using Jason as decoder in my system both directly and through other libraries, one being Postgrex.
My problem is that Postgrex only allows decoding json and jsonb columns with keys being strings.
My other libraries decodes keys as atoms, so when I have decoded json as a map in a function, I have to know if it came from the database or some other source, which is a pain.
So I propose that it can be configured in Postgrex to use atoms as keys.
Jason at least allows this in it's decode function with option: keys: :atoms.

Cheers
  Søren

José Valim

unread,
Oct 21, 2024, 7:27:43 AM10/21/24
to elixi...@googlegroups.com
The best way is to define your own module, that wraps Jason, and set that as the encoder/decoder. :)

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/79ea5ae3-936d-45dd-a213-39509c5ecbe1n%40googlegroups.com.

Søren Hilmer

unread,
Oct 21, 2024, 7:30:00 AM10/21/24
to elixir-ecto
Ahh, of course, nice solution. I was about to fork Postgrex :-)
Thank you
  Søren
Reply all
Reply to author
Forward
0 new messages