semmitmondo
How to decode a JSON object into a keyword list while preserving the same key order?
How to decode a JSON object into a, for instance, keyword list while preserving the same key order that the JSON string uses?
Elixir maps lose this information because of the underlaying Erlang map implementation.
Most Liked
aseigo
According to the JSON specification, JSON objects are unordered. So if you get the same ordering, it is entirely coincidental or an implementation detail of the underlying library. But you can not rely on ordering of the entries there since they are, by specification, not ordered.
You may want to considering using a list instead if the ordering is absolutely required.
thiagoramos
By the way I had a problem where I had to get the json ordered.
I found out we can use Jason.decode(json_string, %{objects: :ordered_objects})
LostKobrakai
Why combine the data for the key into a string just to need a regex to separate it again. You can have a key like {count, key} in elixir maps.
Popular in Questions
Other popular topics
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









