tiye
1
Since Rust uses enums for union types, I can express a nested structure with
enum A {
B(String),
C(Vec<String>),
}
however, to expression JSON structures, which would be really dynamic, one might need to handle structure like:
[
"a",
["b", "c"],
["d", "e", ["f"]],
]
is there a solution for such an arbitrary structure?
or any other solution that is simpler than enum to use when I was to expression such a structure?
alice
2
Sure, if you check out serde_json::Value
, you will find an enum with all the appropriate variants to express any valid JSON.
1 Like
tiye
3
searched docs again and notice that Value type... it's simpler now.
qaopm
4
FYI depending on your needs, using json!
macro can save you a lot of boilerplate/typing when constructing serde_json::Value
s.
1 Like
system
Closed
5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.