How to parse JSON array of arrays of strings and numbers?

How to use std.json to parse an array of arrays of strings and numbers. Specifically the “cycles” attribute of the JSON below.

If it cannot be parsed, how can I make it ignore the “cycles” attribute?

const Data = []struct {
        name: []u8,
        initial: struct {
            pc: u16,
            sp: u16,
            a: u8,
            b: u8,
            c: u8,
            d: u8,
            e: u8,
            f: u8,
            h: u8,
            l: u8,
            ime: u32,
            ie: u32,
            ram: [][]u16,
        },
        final: struct {
            pc: u16,
            sp: u16,
            a: u8,
            b: u8,
            c: u8,
            d: u8,
            e: u8,
            f: u8,
            h: u8,
            l: u8,
            ime: u32,
            ram: [][]u16,
        },
        cycles: [][][]u8,
    };

const result = try std.json.parseFromSlice(Data, std.testing.allocator, data, .{});

[
    {
        "name": "00 0000",
        "initial": {
            "pc": 19935,
            "sp": 59438,
            "a": 110,
            "b": 185,
            "c": 144,
            "d": 208,
            "e": 190,
            "f": 240,
            "h": 131,
            "l": 147,
            "ime": 1,
            "ie": 1,
            "ram": [
                [
                    19935,
                    0
                ]
            ]
        },
        "final": {
            "a": 110,
            "b": 185,
            "c": 144,
            "d": 208,
            "e": 190,
            "f": 240,
            "h": 131,
            "l": 147,
            "pc": 19936,
            "sp": 59438,
            "ime": 1,
            "ram": [
                [
                    19935,
                    0
                ]
            ]
        },
        "cycles": [
            [
                19935,
                0,
                "r-m"
            ]
        ]
    },

    ...(more)

I think this would work:

cycles: [][]std.json.Value,

Then switch on the union.

2 Likes