Parsing JSON manually
⚓ Rust 📅 2025-12-29 👤 surdeus 👁️ 5This is a general algorithm question. Not necessarily specific to Rust, or any other programming language.
Let's say you do not have a JSON serializer/deserializer in the context you are working in.
To make this a little simpler the only JSON structure we are dealing with here is an Array.
You can receive up to 64 MiB of JSON Array data in the form of a buffer. You can decode that buffer to a string if you want. Or just read each character from the buffer.
You can only echo or otherwise send out 1 MiB at a time.
So, you have to figure out a way to find the comma closest to, though before the 1048576th character/index in the buffer, replace that comma with a ], send that sliced text/buffer out, and proceed with the next part of the JSON, inserting a [, finding the next 1048576th index, if it exists, insert another ], repeat until end of text/buffer.
How would you go about doing that process?
3 posts - 2 participants
🏷️ Rust_feed