Decode a JSON object of unknown format into a Dictionary with Decodable in Swift 4

To come back to your original question, I think the best way right now is just to use some JSON enum, similar to the one from itaiferber's gist he referred to earlier in this thread. You can use the implementations of init(from:) and encode(to:) in this gist to extend e.g. Argo's JSON enum to conform to Codable by just changing two words (.dictionary to .object). If you have such an enum, you would decode metadata as [String:JSON].

Depending on what you want to do with this metadata later, you could also use a new meta data structure or enum, whose init(from:) method could look like this:

init(from decoder: Decoder) throws {
    let container = decoder.singleValueContainer()
    let meta = try container.decode([String:JSON].self)

    // e.g. look for keys in meta and then chose for example a case of this enum
}

This is just a summary of the previous answers I think, but in my understanding it should be enough to solve your issue.