Problems serializing a nested array using serve

Hey everyone!
I'm trying to parse information about YouTube playlists as they are given by yt-dlp with the command yt-dlp -j url
(these examples are simplified)

The json it gives out regarding a playlist's format information looks something like this:

{
    "id": "...",
    "title": "Testing",
    "entries": [
        {
          "id": "...",
          "title": "First Video Title",
          "formats": [
              {
                 format1_for_video1: "!!!"
              },
              {
                 format2_for_video1: "!!!"
              }
           ]
        },
        {
          "id": "...",
          "title": "Second Video Title",
          "formats": [
              {
                 format1_for_video2: "!!!"
              },
              {
                 format2_for_video2: "!!!"
              }
           ]
        }
    ]
}

What I need is a structure which can hold all the Videos in a playlist, each one having its own list of formats

In this example that would look something like this

all_videos {
    video_1: [
        format_1: [...]
        format_2: [...]
    ]
    video_2: [
        format_1: [...]
        format_2: [...]
    ]
}

I've tried implementing it like this:

A structure which holds all the information I need about a particular format:

#[derive(Deserialize, Serialize, Debug, PartialOrd, PartialEq)]
struct VideoFormat {
    title: String,
    fps: f64
    ....
}

Something which represent a Video, which can support multiple formats:

#[derive(Deserialize, Serialize, Debug)]
struct VideoSpecs {
    formats: Vec<VideoFormat>,
}

My problem is that I can't parse the "entries" array properly because none of the videos have a name, since they are just elements of an array in the JSON.
For example I've tried doing something like this:

#[derive(Deserialize, Serialize, Debug)]
struct dummy {
    entries: Vec<VideoSpecs>,
}

but I get errors like this:

invalid type: null, expected struct VideoSpecs at line 1 column 1573533

(the full json is very long and only on 1 line)

Does anyone know how I could do this? Maybe some way of ignoring variable names (?)

Thank you for reading : )

You are simply deriving the implementations for Deserialize and Serialize which requires that the serialised data has the same shape as in your Rust code.

If you want a different shape, then you'll need to implement the deserializer yourself.

Thank you, I will look into it

Looks like array in entries can have null entries, not only valid VideoSpecs objects. In this case, you have to either deserialize it manually, skipping nulls (you may want to use deserialize_with attribute for it), or map it to Vec<Option<VideoSpecs>> to preserve nulls as-is.