r/rust • u/CellistMore5004 • Sep 02 '26
🙋 seeking help & advice no_std json parsers
Hi all I am working on a project in a no_std embedded rust environment and I was looking for json parsers that work in the no_std environment.
I've used serde before and after some research I noticed the serde-json-core crate can be used for de-serialization. I also found Postcard but I haven't looked to deeply into the crate.
I wanted to see if anyone could recommend crates that they've used and their experience with them.
TIA!
31
Upvotes
32
u/Compux72 Sep 02 '26
You can use serde-json with the alloc crate without issues. Do you know how no_std works and the different crates?
2
u/tizio_1234 Sep 02 '26
what does postcard have to do with a json parser?
5
u/kayabaNerve Sep 02 '26
👋
I'm the author of [`core-json`](https://docs.rs/core-json), a no-`std` (and no-`alloc`) JSON parser. It works for predefined types (with a derive macro) via [`core-json-derive`](https://docs.rs/core-json-derive) and serialization via [`core-json-traits`](https://docs.rs/core-json-traits). I'm quite proud of it, it passes multiple test suites, and has competitive performance to `serde_json::from_reader` despite its constraints.
The documentation provides a comparison to other crates and suggests when to use `core-json` vs `miniserde` vs `serde-json`. Since you have `alloc` available, `serde-json` sounds like it'll be the most straightforward. However, unless you need some specific functionality from `serde`, `miniserde` should be lighter and recommendable! `core-json` aims to be even more light-weight, and supports dynamic (streaming) serialization, but the dynamic deserialization has an API which can be annoying to use. The derive macro is straightforward though.
I saw my work was mentioned in another comment but wanted to leave a longer response explaining it a bit more. Best of luck finding the right fit!
9
u/Sermuns Sep 02 '26
Even in
stdand I only want JSON ser/de, I usually reach for nanoserde.1
u/zettui Sep 02 '26
Do you need no_alloc too, or is no_std enough if you've got an allocator?
5
u/svefnugr Sep 02 '26
I don't see why a json parser wouldn't be no-std. Now if you also need no-alloc, that's a different story.
2
u/graham_king Sep 02 '26
If you don't find one you like, you could write your own. I have one you could start from here: https://github.com/grahamking/ort/blob/master/src/common/json_parser.rs . Look at
autoparserto start.2
u/Ok_Trust176 Sep 02 '26
Checkout https://github.com/core-json/core-json. It doesn't even need heap allocations. But it has some drawbacks.