Coder Social home page Coder Social logo

skewer's Introduction

Skewer 🍡

Release License Issues Downloads

Provides support for "kebab-case" formatted (as opposed to just "snake_case" formatted) coding keys for JSONEncoder and JSONDecoder.

Encoding

struct Website: Encodable {
    let homepageURLString: String
}

let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToKebabCase

let website = Website(homepageURLString: "http://www.apple.com")
let data = try! encoder.encode(website)
let json = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
let convertedKey = json.keys.first!
// homepage-url-string

Decoding

struct App: Decodable {
    let downloadCount: Int
}

let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromKebabCase

let json = ["download-count": 999]
let data = try! JSONSerialization.data(withJSONObject: json, options: [])
let app = try! decoder.decode(App.self, from: data)
let downloadCount = app.downloadCount
// 999

Installation

Using the Swift Package Manager

Add Skewer as a dependency to your Package.swift file. For more information, see the Swift Package Manager documentation.

.package(url: "https://github.com/Fleuronic/Skewer", from: "3.0.0")

License

Skewer is available under the MIT license. See the LICENSE file for more info.

skewer's People

Contributors

jordanekay avatar

Stargazers

tokorom avatar Emilio Ojeda avatar  avatar Denis Freerider avatar Philip B. avatar Seb Jachec avatar Bojan Dimovski avatar Austin Jackson avatar Christopher Beloch avatar Qutaibah Essa avatar Abiú Roldán avatar HolyShit avatar Antony Alkmim avatar Jesse Youngblood avatar A avatar Tim Oliver avatar Oliver avatar Cody avatar Mark Anderson avatar Krishna avatar Farhan Yuda Pahlevi avatar Alexander Murphy avatar Bradley Mackey avatar Tim Kersey avatar Will Su avatar George J avatar Witek Bobrowski avatar Astemir Eleev avatar Guilherme Rambo avatar Brandon Evans avatar  avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

haikusw

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.