How to express nested vectors in Rust or Rust JSON

Since Rust uses enums for union types, I can express a nested structure with

enum A {

however, to expression JSON structures, which would be really dynamic, one might need to handle structure like:

  ["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?

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

searched docs again and notice that Value type... it's simpler now.

FYI depending on your needs, using json! macro can save you a lot of boilerplate/typing when constructing serde_json::Values.

1 Like

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.