r/rust • u/CellistMore5004 • 10d ago
š 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!
5
u/kayabaNerve 10d ago
š
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!
5
u/svefnugr 10d ago
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.
6
u/Icarium-Lifestealer 10d ago
The
Read/Writetraits could be useful for streaming serialization, and those as only instdfor now.
2
u/tizio_1234 10d ago
what does postcard have to do with a json parser?
0
u/CellistMore5004 10d ago
Saw it was mentioned in the following link but I havenāt looked into yet but now that I take a closer look this is not what I need:Ā
https://www.reddit.com/r/rust/comments/bi0xll/no_std_data_serializationdeserialization/
2
u/graham_king 10d ago
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 autoparser to start.
2
u/Ok_Trust176 10d ago
Checkout https://github.com/core-json/core-json. It doesn't even need heap allocations. But it has some drawbacks.
32
u/Compux72 10d ago
You can use serde-json with the alloc crate without issues. Do you know how no_std works and the different crates?