since json has strict type
theoretically is should be possible to generate a generic struct right? like given {"a":[1,2]}
we can generate a struct.
so it can be re-created more easily and dont need to wasting typing boilerplate code right?
somearray=[1,2];
somejsonobject.add("a",somarray)
something like this would be possible to re-create the json right?
Is there a downside for doing this?Why no json library implemented this feature/function?
as like generatestruct(String inputjsonpath);
It is unclear what you are asking. If you mean whether it's possible to generate serialization and deserialization boilerplate for user-defined types, then this is exactly what Serde's derive macros do.
That is similar to I wanted,BTW is the dependencies also something like?
I dont really know how to properly build the cargo dependencies mapping.
serde_json = { version = "1.0.82", default-features = false, features = ["alloc"] }
how do we include the derive(Debug, Serialize, Deserialize)] thingy?
Ideally I want to let computer simply figuring out the WHOLE struct by itself.
Since honestly,it should be very obvious what type it is or can just use a type that they can fallback to.
for example in the link the json is>
JSON: {
"field1": "this is a string",
"field2": [
1,
2,
3
]
}