NobbZ
I have a huge binary, containing multiple json documents. Is there a way to parse them using jason (or any other json-parser) into a list?
eg, make the result of Jason.decode("{}{}") equivalent to Jason.decode("[{},{}]")?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
amnu3387
You asked specifically for using a parser to do it, but I’m not aware of any that can do that. You probably know better than I how to work with binaries and charlists, but anyway I would use something like this:
I don’t know though if charlist is faster for this case where the binary is small itself, and if the charlist being the same if it’s held in memory while for the binary it might not? I think you would need to benchmark them with some real variable blobs and see for yourself, with this setup charlists were faster:
NobbZ
Yeah, I went this route as well (though splitting the blob into many strings I
Enum.map/2over), but it annoys me, that I have to do pretty much the same thing the parser does anyway (counting parens that are not in a string).Id be happy with something that would roughly do this:
{:ok, #{}, "{}"} = imaginary_parser("{}{}"), such that I can consume the remainder until it becomes""and therefore I know I have parsed the full input stream.arjan
Have you looked at Jaxon? Seems like it might do what you want.
Eiji
@NobbZ Here is my suggestion:
This module automatically tries to fix:
[at start ofJSON,between twoJSONobjects]at end ofJSONUnfortunately automatically fix missing
[and]characters deeply is a bit hard for me based onJasonerrors.Let me know if it helps.
@AstonJ Is it my bad or we have problem with multi line text highlighting?
AstonJ
What do you mean Tomasz? The code block above? It’s all there, you just have to scroll
Eiji
Not scroll, by text highlighting I mean syntax highlighting - just take a look at it:
AstonJ
Ah I see what you mean. Discourse uses highlight.js, so changes would need to be made there and then Discourse should pick the new version
https://github.com/highlightjs/highlight.js/blob/master/src/languages/elixir.js
@knewter is the author, perhaps he could help?
dimitarvp
Are you able to find a way to reliably split the separate documents by newline in the string blob? Replacing
"}{"with"}\n{"might work depending on the input data (but is sadly likely very fragile solution).If you manage to achieve separation then just parsing the JSON documents line by line should be extremely easy:
Which would give you a bunch of
{:ok, document}or{:error, reason}tuples in a list.