Implement dynamic JSON decoding within the constraints of Swift's sound type system by working on top of Swift's Codable implementations.

Overview

DynamicCodableKit

API Docs CocoaPods Compatible Swift Package Manager Compatible Carthage compatible Swift Platforms CI/CD CodeQL Maintainability codecov

DynamicCodableKit helps you to implement dynamic JSON decoding within the constraints of Swift's sound type system by working on top of Swift's Codable implementations.

The data types, protocols, and property wrappers defined by DynamicCodableKit can be used to provide dynamic decoding functionality to swift's Decodable types.

Features

  • Decode dynamic type based on JSON keys.
  • Decode dynamic type based on parent JSON key.
  • Dynamically decode types with default value if decoding fails.
  • Decode dynamic type array/set with option to ignore invalid elements.
  • Decode dynamic data based on user actions.

Requirements

Platform Minimum Swift Version Installation Status
iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ 5.1 CocoaPods, Carthage, Swift Package Manager, Manual Fully Tested
Linux 5.1 Swift Package Manager Fully Tested
Windows 5.3 Swift Package Manager Fully Tested

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate DynamicCodableKit into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'DynamicCodableKit'

Optionally, you can also use the pre-built XCFramework from the GitHub releases page by replacing {version} with the required version you want to use:

pod 'DynamicCodableKit', :http => 'https://github.com/SwiftyLab/DynamicCodableKit/releases/download/v{version}/DynamicCodableKit-{version}.xcframework.zip'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate DynamicCodableKit into your Xcode project using Carthage, specify it in your Cartfile:

github "SwiftyLab/DynamicCodableKit"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding DynamicCodableKit as a dependency is as easy as adding it to the dependencies value of your Package.swift.

.package(url: "https://github.com/SwiftyLab/DynamicCodableKit.git", from: "1.0.0"),

Optionally, you can also use the pre-built XCFramework from the GitHub releases page by replacing {version} and {checksum} with the required version and checksum of artifact you want to use:

.binaryTarget(name: "DynamicCodableKit", url: "https://github.com/SwiftyLab/DynamicCodableKit/releases/download/v{version}/DynamicCodableKit-{version}.xcframework.zip", checksum: "{checksum}"),

Manually

If you prefer not to use any of the aforementioned dependency managers, you can integrate DynamicCodableKit into your project manually.

Git Submodule

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:

    $ git init
  • Add DynamicCodableKit as a git submodule by running the following command:

    $ git submodule add https://github.com/SwiftyLab/DynamicCodableKit.git
  • Open the new DynamicCodableKit folder, and drag the DynamicCodableKit.xcodeproj into the Project Navigator of your application's Xcode project or existing workspace.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the DynamicCodableKit.xcodeproj in the Project Navigator and verify the deployment target satisfies that of your application target (should be less or equal).

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the Targets heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the Frameworks and Libraries section.

  • You will see DynamicCodableKit.xcodeproj folder with DynamicCodableKit.framework nested inside.

  • Select the DynamicCodableKit.framework and that's it!

    The DynamicCodableKit.framework is automagically added as a target dependency, linked framework and embedded framework in build phase which is all you need to build on the simulator and a device.

XCFramework

You can also directly download the pre-built artifact from the GitHub releases page:

  • Download the artifact from the GitHub releases page of the format DynamicCodableKit-{version}.xcframework.zip where {version} is the version you want to use.

  • Extract the XCFramework from the archive, and drag the DynamicCodableKit.xcframework into the Project Navigator of your application's target folder in your Xcode project.

  • Select Copy items if needed and that's it!

    The DynamicCodableKit.xcframework is automagically added in the embedded Frameworks and Libraries section, an in turn the linked framework in build phase.

Usage

See the full documentation for API details and articles on sample scenarios.

Contributing

If you wish to contribute a change, suggest any improvements, please review our contribution guide, check for open issues, if it is already being worked upon or open a pull request.

License

DynamicCodableKit is released under the MIT license. See LICENSE for details.

You might also like...
Swift-json - High-performance json parsing in swift

json 0.1.4 swift-json is a pure-Swift JSON parsing library designed for high-per

Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON.

JSONFeed Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON. For more information about this new feed format visit: https:/

Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend
Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend

Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend. Using Argo

A type-safe JSON-RPC 2.0 library purely written in Swift

JSONRPCKit JSONRPCKit is a type-safe JSON-RPC 2.0 library purely written in Swift. // Generating request JSON let batchFactory = BatchFactory(version:

SwiftyJSON decoder for Codable

SwiftyJSONDecoder 功能 继承自 JSONDecoder,在标准库源码基础上做了改动,与其主要区别如下 使用 SwiftyJSON 解析数据,使用其类型兼容功能 废弃 nonConformingFloatDecodingStrategy 属性设置,Double 及 Float 默认解

AlamofireObjectMappe - An Alamofire extension which converts JSON response data into swift objects using ObjectMapper

AlamofireObjectMapper An extension to Alamofire which automatically converts JSON response data into swift objects using ObjectMapper. Usage Given a U

Functional JSON Parser - Linux Ready
Functional JSON Parser - Linux Ready

Functional JSON Parser Feature Linux Ready Type-safe JSON parsing Functional value transformation Easy to parse nested value Dependency free No define

Arrow  🏹 Parse JSON with style
Arrow 🏹 Parse JSON with style

Arrow 🏹 Parse JSON with style

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. Elevate should no longer be used for

Comments
  • ci(Deps): bump JamesIves/github-pages-deploy-action from 4.3.3 to 4.3.4

    ci(Deps): bump JamesIves/github-pages-deploy-action from 4.3.3 to 4.3.4

    Bumps JamesIves/github-pages-deploy-action from 4.3.3 to 4.3.4.

    Release notes

    Sourced from JamesIves/github-pages-deploy-action's releases.

    v4.3.4

    Minor Changes

    • The branch parameter is no longer required. It now defaults to gh-pages.
    • Linting scripts have been updated to ensure that everything across the repo gets picked up.
    • Numerous dependency updates.

    New Contributors

    Sponsors ❤️

      

    Full Changelog: https://github.com/JamesIves/github-pages-deploy-action/compare/v4...v4.3.4

    Commits
    • e6d003d Deploy Production Code for Commit 95ad738c59a06cd63bac926396b36bb932c6c0c8 🚀
    • 95ad738 Merge branch 'dev' into releases/v4
    • face238 Prettier ignore
    • 95ff531 Use major version tags (#1152)
    • d45cebd Fix lint scripts (#1154)
    • c0e8d73 Set default branch to gh-pages (fix #1151) (#1155)
    • f7f029d Deploying to dev from @ JamesIves/github-pages-deploy-action@b6e885503b3ff910...
    • b6e8855 Update sponsors.yml
    • 8728dd1 Deploying to dev from @ JamesIves/github-pages-deploy-action@f86c712e7cfd763b...
    • f86c712 Update sponsors.yml
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 0
  • ci(Deps): bump @actions/core from 1.8.2 to 1.9.0

    ci(Deps): bump @actions/core from 1.8.2 to 1.9.0

    Bumps @actions/core from 1.8.2 to 1.9.0.

    Changelog

    Sourced from @​actions/core's changelog.

    1.9.0

    • Added toPosixPath, toWin32Path and toPlatformPath utilities #1102
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies javascript 
    opened by dependabot[bot] 0
  • ci(Deps): bump conventional-changelog-conventionalcommits from 4.6.3 to 5.0.0

    ci(Deps): bump conventional-changelog-conventionalcommits from 4.6.3 to 5.0.0

    Bumps conventional-changelog-conventionalcommits from 4.6.3 to 5.0.0.

    Release notes

    Sourced from conventional-changelog-conventionalcommits's releases.

    conventional-changelog-conventionalcommits: v5.0.0

    5.0.0 (2022-05-27)

    ⚠ BREAKING CHANGES

    • always use H2 heading for versions (#920)

    Bug Fixes

    Changelog

    Sourced from conventional-changelog-conventionalcommits's changelog.

    { "packages/conventional-changelog-conventionalcommits": "5.0.0", "packages/conventional-changelog-cli": "2.2.2", "packages/conventional-changelog": "3.1.25", "packages/conventional-commits-parser": "3.2.4", "packages/git-raw-commits": "2.0.11", "packages/conventional-changelog-writer": "5.0.1" }

    Commits
    • ba6df7c chore(master): release conventional-changelog-conventionalcommits 5.0.0 (#921)
    • d2e02d7 fix!: always use H2 heading for versions (#920)
    • 21b73f9 chore(master): release conventional-changelog-writer 5.0.1 (#897)
    • e946182 build: downgrade action script to v4
    • 1cfc3a1 fix(deps): patch the handlebars package for CVE-2021-23369
    • 2aa7626 chore(deps): update actions/github-script action to v5 (#855)
    • 6455ab7 docs: add emacs-plugin (#863)
    • 593307e build: use release-please v3
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies javascript 
    opened by dependabot[bot] 0
  • ci(Deps): bump codecov/codecov-action from 2.1.0 to 3.1.0

    ci(Deps): bump codecov/codecov-action from 2.1.0 to 3.1.0

    Bumps codecov/codecov-action from 2.1.0 to 3.1.0.

    Release notes

    Sourced from codecov/codecov-action's releases.

    v3.1.0

    3.1.0

    Features

    • #699 Incorporate xcode arguments for the Codecov uploader

    Dependencies

    • #694 build(deps-dev): bump @​vercel/ncc from 0.33.3 to 0.33.4
    • #696 build(deps-dev): bump @​types/node from 17.0.23 to 17.0.25
    • #698 build(deps-dev): bump jest-junit from 13.0.0 to 13.2.0

    v3.0.0

    Breaking Changes

    • #689 Bump to node16 and small fixes

    Features

    • #688 Incorporate gcov arguments for the Codecov uploader

    Dependencies

    • #548 build(deps-dev): bump jest-junit from 12.2.0 to 13.0.0
    • #603 [Snyk] Upgrade @​actions/core from 1.5.0 to 1.6.0
    • #628 build(deps): bump node-fetch from 2.6.1 to 3.1.1
    • #634 build(deps): bump node-fetch from 3.1.1 to 3.2.0
    • #636 build(deps): bump openpgp from 5.0.1 to 5.1.0
    • #652 build(deps-dev): bump @​vercel/ncc from 0.30.0 to 0.33.3
    • #653 build(deps-dev): bump @​types/node from 16.11.21 to 17.0.18
    • #659 build(deps-dev): bump @​types/jest from 27.4.0 to 27.4.1
    • #667 build(deps): bump actions/checkout from 2 to 3
    • #673 build(deps): bump node-fetch from 3.2.0 to 3.2.3
    • #683 build(deps): bump minimist from 1.2.5 to 1.2.6
    • #685 build(deps): bump @​actions/github from 5.0.0 to 5.0.1
    • #681 build(deps-dev): bump @​types/node from 17.0.18 to 17.0.23
    • #682 build(deps-dev): bump typescript from 4.5.5 to 4.6.3
    • #676 build(deps): bump @​actions/exec from 1.1.0 to 1.1.1
    • #675 build(deps): bump openpgp from 5.1.0 to 5.2.1
    Changelog

    Sourced from codecov/codecov-action's changelog.

    3.1.0

    Features

    • #699 Incorporate xcode arguments for the Codecov uploader

    Dependencies

    • #694 build(deps-dev): bump @​vercel/ncc from 0.33.3 to 0.33.4
    • #696 build(deps-dev): bump @​types/node from 17.0.23 to 17.0.25
    • #698 build(deps-dev): bump jest-junit from 13.0.0 to 13.2.0

    3.0.0

    Breaking Changes

    • #689 Bump to node16 and small fixes

    Features

    • #688 Incorporate gcov arguments for the Codecov uploader

    Dependencies

    • #548 build(deps-dev): bump jest-junit from 12.2.0 to 13.0.0
    • #603 [Snyk] Upgrade @​actions/core from 1.5.0 to 1.6.0
    • #628 build(deps): bump node-fetch from 2.6.1 to 3.1.1
    • #634 build(deps): bump node-fetch from 3.1.1 to 3.2.0
    • #636 build(deps): bump openpgp from 5.0.1 to 5.1.0
    • #652 build(deps-dev): bump @​vercel/ncc from 0.30.0 to 0.33.3
    • #653 build(deps-dev): bump @​types/node from 16.11.21 to 17.0.18
    • #659 build(deps-dev): bump @​types/jest from 27.4.0 to 27.4.1
    • #667 build(deps): bump actions/checkout from 2 to 3
    • #673 build(deps): bump node-fetch from 3.2.0 to 3.2.3
    • #683 build(deps): bump minimist from 1.2.5 to 1.2.6
    • #685 build(deps): bump @​actions/github from 5.0.0 to 5.0.1
    • #681 build(deps-dev): bump @​types/node from 17.0.18 to 17.0.23
    • #682 build(deps-dev): bump typescript from 4.5.5 to 4.6.3
    • #676 build(deps): bump @​actions/exec from 1.1.0 to 1.1.1
    • #675 build(deps): bump openpgp from 5.1.0 to 5.2.1
    Commits
    • 81cd2dc Merge pull request #699 from codecov/feat-xcode
    • a03184e feat: add xcode support
    • 6a6a9ae Merge pull request #694 from codecov/dependabot/npm_and_yarn/vercel/ncc-0.33.4
    • 92a872a Merge pull request #696 from codecov/dependabot/npm_and_yarn/types/node-17.0.25
    • 43a9c18 Merge pull request #698 from codecov/dependabot/npm_and_yarn/jest-junit-13.2.0
    • 13ce822 Merge pull request #690 from codecov/ci-v3
    • 4d6dbaa build(deps-dev): bump jest-junit from 13.0.0 to 13.2.0
    • 98f0f19 build(deps-dev): bump @​types/node from 17.0.23 to 17.0.25
    • d3021d9 build(deps-dev): bump @​vercel/ncc from 0.33.3 to 0.33.4
    • 2c83f35 Update makefile to v3
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 0
Releases(v1.0.0)
🧱 A JSON decoding/encoding library that handles optimistically or strictly.

Do you need to handle the root cause of failure in decoding JSON? We often process the value as a default value if it could not be decoded from JSON.

Muukii 252 Oct 28, 2022
Nikolai Saganenko 1 Jan 9, 2022
Hassle-free JSON encoding and decoding in Swift

#JSONCodable Hassle-free JSON encoding and decoding in Swift Installation Simply add the following to your Cartfile and run carthage update: github "m

Matthew Cheok 605 Jun 29, 2022
Library of Swiftui Views conforming to Codable, meaning we can produce JSON driven UI!

CodableView Library of Swiftui Views conforming to Codable, meaning we can produce JSON driven UI! Adding a CodableView Type Create View that conforms

Daniel Bolella 3 Apr 2, 2022
Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs

Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs.

Julio Cesar Guzman Villanueva 2 Oct 6, 2022
A protocol to serialize Swift structs and classes for encoding and decoding.

Serpent (previously known as Serializable) is a framework made for creating model objects or structs that can be easily serialized and deserialized fr

Nodes - iOS 287 Nov 11, 2022
JSONNeverDie - Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die

JSONNeverDie is an auto reflection tool from JSON to Model, a user friendly JSON encoder / decoder, aims to never die. Also JSONNeverDie is a very important part of Pitaya.

John Lui 454 Oct 30, 2022
JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /ˈdʒeɪsən/ JAY-sən JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

Roger Oba 8 Nov 22, 2022
JSON-Practice - JSON Practice With Swift

JSON Practice Vista creada con: Programmatic + AutoLayout Breve explicación de l

Vanesa Giselle Korbenfeld 0 Oct 29, 2021
Ss-json - High-performance json parsing in swift

json 0.1.1 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022