Skip to content

Fleuronic/Skewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Ā 

History

25 Commits
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 

Repository files navigation

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.

About

šŸ” Automatic support for ā€œkebab-caseā€ in Swift JSON encoders and decoders

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages