Swiftpack.co -  mochidev/DynamicCodable as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Easily preserve arbitrary Codable data structures when unarchiving
.package(url: "https://github.com/mochidev/DynamicCodable.git", from: "1.1.0")


Test Status

DynamicCodable aims to make it easy to preserve arbitrary Codable data structures when unarchiving, allowing you to inspect those structures in a type safe way after the decoding is finished.


Add DynamicCodable as a dependency in your Package.swift file to start using it. Then, add import DynamicCodable to any file you wish to use the library in.

Please check the releases for recommended versions.

dependencies: [
    .package(url: "https://github.com/mochidev/DynamicCodable.git", .upToNextMinor(from: "1.0.0")),
targets: [
        name: "MyPackage",
        dependencies: [

What is DynamicCodable?

DynamicCodable is an enumeration that represents the various primitive types that are themselves codable. Using it is easy — simply mark the portion of your graph as being of type DynamicCodable to enable that subtree to be preserved during decoding:

struct ServerResponse: Codable {
    let status: String
    let metadata: DynamicCodable

let response = try JSONDecoder().decode(ServerResponse.self, from: data)

// Consume the metadata whole

// Dig into the metadata — it's just an enum!
switch response.metadata {
case .keyed(let dictionary)
    print(dictionary["debugInfo"], default: .empty) // Convenience for dictionary[.string("debugInfo"), default: .empty]
case .bool(false):
    print("Metadata disabled")
case .nil:
    print("Metadata unavailable")
default: break

Note that DynamicCodable is not limited to be used with JSON coders - it can be used with any Codable-compatible coder!


Contribution is welcome! Please take a look at the issues already available, or start a new issue to discuss a new feature. Although guarantees can't be made regarding feature requests, PRs that fit with the goals of the project and that have been discussed before hand are more than welcome!

Please make sure that all submissions have clean commit histories, are well documented, and thoroughly tested. Please rebase your PR before submission rather than merge in main. Linear histories are required.


Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

2 weeks ago
  • Fixed an issue where testing on 32-bit would not compile.
  • Fixed minimum swift version to 5.3 due to usage of Comparable.
  • Added support for literals when composing DynamicCodable manually.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API