How do I deserialize a JSON array without needing a wrapper type?

sargas

I want to deserialize the following JSON:

[
  {
    "name": "one",
    "path": "/path/to/one"
  },
  {
    "name": "two",
    "path": "/path/to/two"
  },
  {
    "name": "three",
    "path": "/path/to/three"
  }
]

Into a Vec<Worskpace>. Workspace is defined below:

#[derive(Serialize, Deserialize)]
struct Workspace {
    name: String,
    path: String,
}

Is there a way to do that without having to do something like:

#[derive(Serialize, Deserialize)]
struct Workspacesss {
    values: Vec<Workspace>,
}
Shepmaster

Just deserialize the vector directly:

let workspaces = serde_json::from_str::<Vec<Workspace>>(input);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I type "cargo run" without needing to set the LD_LIBRARY_PATH shell variable?

How can I use Google GSON to deserialize a JSON array into a a Collection of a generic type?

How do I deserialize a nested JSON array using GSON?

How do I deserialize a JSON array that contains only values?

How do I deserialize a JSON array using Newtonsoft.Json

How can I serialize and deserialize a type with a string member that contains "raw" JSON, without escaping the JSON in the process

How do I deserialize into trait, not a concrete type?

How do I deserialize an array of JSON objects to a C# anonymous type?

How do I deserialize a JSON array(flat) and ignore some token

How do I deserialize a JSON representation containing array of objects using jackson?

How do I render an Array of Strings in React without using wrapper?

How do I deserialize JSON with optional properties?

How to deserialize array into wrapper object?

How do I resolve "implementation of serde::Deserialize is not general enough" with actix-web's Json type?

How do I deserialize a json with nested array in c# using Newtonsoft.Json

How do I deserialize json so that some json properties gets assigned to an array or List?

How do I deserialize a Json object?

How do I deserialize an array of JSON data into a POJO using an abstract class?

How do I deserialize this type of data structure

How do I use kwargs as flags without needing =True?

How can I deserialize json array?

How do I get C++ signaling_nan() to throw an exception, without needing if tests?

How do I get System.Text.Json to deserialize objects into their original type?

How can I add type hints for kwargs that are passed to another class without needing to duplicate my hints and/or docs?

In C#.NET, how do I deserialize a JSON object that is not an array of objects, and has a unique name for every object?

How do you declare the type a property of an object in-place, without needing to declare the type of the entire object?

How do I type correctly a wrapper function?

How to deserialize array in the xml to different object types without type attribute?

How do I deserialize JSON where there is an array of ane/value properties along with a Location which has three values?