joges
After querying database tables from amazon ledger database via python/erlport I get a list of amazon ion objects like
[
'"{subject:\\"Elixir\\",state:\\"in use\\",url:\\"https://forum.elixirforum.com",retrieved_on:2019-12-21T00:00:00.000000-00:00}"',
'"{subject:\\"Phoenix\\",state:\\"in use\\",url:\\"https://www.phoenixframework.org",retrieved_on:2019-12-21T00:00:00.000000-00:00}"'
]
The objects represent neither elixir types nor valid json.
How can I convert such objects or the list of objects into a list of maps or into json to use in elixir.
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ityonemo
Looks like they are just escaped json. Unescape it, then Jason.decode
joges
You are right. They call it a superset of json.
I have already tryed to use Jason.decode but all I got get was the same list without the leading and closing single quote like:
How can I unescape it?
fuelen
It is not a json, it contains own data structures, like datetime in UTC
retrieved_on:2019-12-21T00:00:00.000000-00:00, so Jason isn’t able to parse this.@joges you need your own parser or just do deserialization into JSON on python side.
ityonemo
ha, I was on mobile so didn’t see that far into the data structure!
+1 on own parser
dimitarvp
How exactly do the objects arrive, in which form?
Do they start with a single quote, or a double quote? It’s not very clear from the snippet you posted in your OP.
Ideally, please post exactly how you see them in
iex. Show us an assignment to a variable and the output in the console.dimitarvp
Here’s a quick and very dirty and unsafe implementation that works on your both samples:
Now test it in
iex:I am not sure if this code properly assumes the shape of the input data though. The assumptions are shown in the hardcoded text samples.
From then on, you can additionally parse the date/times into proper Elixir objects. It’s pretty easy when you use timex.
I’d strongly recommend using something more proper like nimble_parsec for this task though!
joges
The looks like a solution! Many thanks!!
But maybe there is potential for improvements, so in order to answer your questions and in order to explain better what I do on python side:
I have a function on python side, which converts an ion object into python:
When I print this function in python or call it via erlport in elixir and make an IO.inspect() I get the following result in iex (this time with original and not example data):
So in this case, I get a single quoted result.
I also tried to convert this object on python side to json:
The result of “already converted to json on python side” is as I posted before single and double quoted:
dimitarvp
I don’t know Python but this doesn’t look right; it does not even attempt to format the keys to JSON – namely enclose them in double quotes. If you want to just pass a valid JSON to the Elixir code – which you should IMO, and you should ignore my code because it’s unsafe and makes too many assumptions – then fight with your Python code and make it format your key/value pairs as JSON. Shouldn’t be that hard I reckon.
You also have your double quotes strangely escaped: you have the backslash itself escaped. Pretty weird.
joges
Thanks for your help and advise. I am going to play around on python side again. By the way the python side code is an example code snippet directly catched from the amazon python driver example code for the ledger database.
dimitarvp
Eh, I didn’t help much.
I’d additionally advise you to go to StackOverflow and ask how can you format Amazon Ions to valid JSON in Python. Once you have that solved, the Elixir part is a piece of cake – just a matter of
Jason.decode.Good luck!