4 ms·
Nothing in rust actually limits or makes it any harder to handle something "more dynamic" like JSON. In rust you just make a JsonValue enum that represents the
by Permik 3y ago
Nothing in rust actually limits or makes it any harder to handle something "more dynamic" like JSON.
In rust you just make a JsonValue enum that represents the values and the data types that you're handling.
In something like Python, you just use the built-in runtime value type to represent the structure.
Either way you still have to plumb up the data ingestation and your codepaths that you want to use the dynamic data in. For example you still have to check if the "name" key's value is a string and not an object, array etc.
Otherwise, you probably could just use some accessors that access the values willy nilly that coerce them to text, return an error or panic, that could also exist in rust (some of these things you would have to wire up manually, some are provided by the language and others are fixed by just annotating structs.)
To summarize, fail to see the point you're trying to make, do you have some specific example you are thinking of that I can take a look at?
- PartiallyTyped 3y agoYou made my point, in that it is a slightly more involved process over say Python. I didn't say that it's a "problem" or "impossible", just that it is making your life slightly harder. Something that I am interested in doing is generating a json schema at runtime, and then parsing some incoming json to see if that matches the target schema. Do you know of any crate already providing this kind of functionality?
- Permik 3y agoWould something like Valico fit the bill? https://crates.io/crates/valico https://crates.io/crates/valico When looking for crates lib.rs is an excellent search utility for searching crates that you would need. For example: https://lib.rs/search?q=json https://lib.rs/search?q=json
- PartiallyTyped 3y agoTIL lib.rs exists :D I think it fits the bill. I was doing this on python side and aimed to use Pydantic and this looks close enough.