Skip to content

yageek/YGSONEncoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YGSONEncoder

A reimplementation of JSONEncoder to have sortedKeys on pre-iOS 11 (not based on JSONSerialization).

Code largely inspired by:

Current features

  • DateEncodingStrategy
  • DataEncodingStrategy
  • OutputFormatting
  • KeyEncodingStrategy
  • JSONEncoder.NonConformingFloatEncodingStrategy
  • Class inheritance encoding

Usage

struct TestUnsortedStruct: Codable {
       let z: String
       let b: String
       let r: String
       let c: String
}

let element = TestUnsortedStruct(z: "1", b: "2", r: "3", c: "4")
let encoder = YGSONEncoder()
encoder.outputFormatting = [.sortedKeys]

do {
    let data = try encoder.encode(element)
    } catch let error {
        print("Error: \(error)")
}

About

🎯 Swift reimplementation of JSONEncoder

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages