Making a POST request

Trying to make JSON a payload for a POST request

I have a Model that comes from my API

struct Series: Codable, Hashable, Identifiable {
    let id: Int
    let title: String
    let overview: String

    func hash(into hasher: inout Hasher) {
        hasher.combine(id)
    }

    static func == (lhs: Series, rhs: Series) -> Bool {
        lhs.id == rhs.id
    }

    enum CodingKeys: String, CodingKey {
        case id
        case title
        case overview
    }
}

Lets say that I have one already made

let series = Series(...args)

I Need the payload for the post request to look like this

{
     "id: 1,
     "title": "Random title",
     "overview": "This is an overview",
     "additionalField1": 2,
     "additionalField2": false,
     "additionalField3": "red"

}

Is there an easier way to do that insted of this?
(in reality a Series has 50+ fields on it that need to get sent in the payload as well)

let payload = [String, (Int, String, Bool)] = [
    "id": series.id,
    "title": series.title,
    "overview": series.overview,
    "additionalField1": randomVariable1,
    "additionalField2": randomVariable2,
    "additionalField3": randomVariable2
]

I know in javascript I would just do something like:

{
    ...series,
    "additionalField1": randomVariable1,
    "additionalField2": randomVariable2,
    "additionalField3": randomVariable2
}

Ive played around with making another struct

struct AdditionalParams: Codable {
    let additionalField1: Int
    let additionalField2: Bool
    let additionalField3: String
}

But how would I merge AdditionalParams() and Series() together to make the post request?

Based on this suggestion here's a simple "merger" helper:

struct Merger: Encodable {
    let values: [Encodable]
    
    func encode(to encoder: Encoder) throws {
        for value in values {
            try value.encode(to: encoder)
        }
    }
}

let series = Series(id: 123, title: "some title", overview: "some overview")
let additional = AdditionalParams(additionalField1: 1, additionalField2: false, additionalField3: "3")
let v = Merger(values: [series, additional])
                     
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys
let data = try! encoder.encode(v)
let s = String(data: data, encoding: .utf8)!
print(s)
// {"additionalField1":1,"additionalField2":false,"additionalField3":"3","id":123,"overview":"some overview","title":"some title"}

Edit: modified code a bit to support multi-merge.

Last I tried this didn't work, but perhaps Swift 5.7 has made any Encodable useful finally.

Merger compiles fine since swift 4.0 according to godbolt. Note that Encodable has no associated type or self requirement.