Latest 1.1.0
License MIT
Platforms ios 8.0, osx 10.11, tvos 9.0, requires ARC

Build Status
Pod Version
Pod License

SexyJson is Swift4 json parse open source library quickly and easily, perfect supporting class and struct model, support the KVC model, fully oriented protocol architecture, support iOS and MAC OS X

Objective-c version 👉 WHC_Model

update:Support for compatible swift4.2


  • The definition of model must implement SexyJson protocol
  • If you have any enumeration type must be specified in the definition of model data type and implementation SexyJsonEnumType protocol
  • If you want to use swift3.2, please pod SexyJson ‘~> 0.0.4’


  • iOS 8.0+ / Mac OS X 10.11+ / tvOS 9.0+
  • Xcode 8.0 or later
  • Swift 4.2


  • CocoaPods: pod ‘SexyJson’


This is an example of json:

let json = "{"age":25,"enmuStr":"Work","url":"https:\/\/",

The model class:

enum WorkEnum: String,SexyJsonEnumType {
    case null = "nil"
    case one = "Work"
    case two = "Not Work"

enum IntEnum: Int,SexyJsonEnumType {
    case zero = 0
    case hao = 10
    case xxx = 20

struct Model :SexyJson {

    var age: Int = 0
    var enmuStr: WorkEnum!
    var url: URL!
    var subArray: [SubArray]!
    var color: UIColor!
    var nestArray: [[NestArray]]?
    var enmuInt: IntEnum = .xxx
    var sub: Sub!
    var height: Int = 0
    var intArray: [Int]!
    var name: String!
    var learn: [String]!

    /// Model mapping
    public mutating func sexyMap(_ map: [String : Any]) {
        age      <<<   map["age"]
        enmuStr  <<<   map["enmuStr"]
        url      <<<   map["url"]
        subArray <<<   map["subArray"]
        color    <<<   map["color"]
        nestArray <<<  map["nestArray"]
        enmuInt   <<<  map["enmuInt"]
        sub       <<<  map["sub"]
        height    <<<  map["height"]
        intArray  <<<  map["intArray"]
        name      <<<  map["name"]
        learn     <<<  map["learn"]

You don’t need to manually create the SexyJson model class you can use open source tools with the help of automatically created SexyJson model


Json is converted into a model object(json -> model)

let model = Model.sexy_json(json)

Model object converted into the dictionary(model -> dictionary)

let dictionary = model.sexy_dictionary()

Model object converted into the json string(model -> json)

let jsonStr = model.sexy_json()

SexyJson support json parse the key path

let subArrayModel = SubArray.sexy_json(json, keyPath: "subArray[0]")
let subNestArray = NestArray.sexy_json(json, keyPath: "nestArray[0][0]")
let test = String.sexy_json(json, keyPath: "nestArray[0][0].test")

Json is converted into a model array object(json -> [model])

let arrayModel = [Model].sexy_json(json)

Model object array converted into the array([model] -> array)

let array = arrayModel.sexy_array()

Model object array converted into the json string([model] -> json)

let arrayJson = arrayModel.sexy_json()

SexyJson support model kvc( Model class implement Codable protocol )

let sub = Sub.sexy_json(json, keyPath: "sub")
if let modelCodingData = try? JSONEncoder().encode(modelCoding) {
    if let modelUncoding = try? JSONDecoder().decode(Sub.self, from: modelCodingData) {
        print("modelUncodingJson = (modelUncoding.sexy_json()!)")


If you want to view the analytical results, please download this demo to check the specific usage


All source code is licensed under the MIT License.

Latest podspec

    "name": "SexyJson",
    "version": "1.1.0",
    "summary": "SexyJson is Swift4 json parse open quickly and easily, perfect supporting class and struct model, support the KVC model",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "u5434u6d77u8d85(WHC)": "[email protected]"
    "platforms": {
        "ios": "8.0",
        "osx": "10.11",
        "tvos": "9.0"
    "source": {
        "git": "",
        "tag": "1.1.0"
    "source_files": "SexyJsonKit/*.{swift}",
    "requires_arc": true

Pin It on Pinterest

Share This