     ///
     public func serializeAPIToJSON() throws -> String? {
         let encoder = JSONEncoder()
-        encoder.outputFormatting = .prettyPrinted
+        if #available(OSX 10.13, *) {
+            encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
+        } else {
+            // Fallback on earlier versions
+            encoder.outputFormatting = .prettyPrinted
+        }
         let encodedData = try encoder.encode(self)
         var search = "}"
         var json = String(data: encodedData, encoding: .utf8)
         if var unwrappedJson = json {
-            if encoder.outputFormatting == .prettyPrinted {
+            if encoder.outputFormatting.contains(.prettyPrinted) {
                 search = "\n}"
             }
             if let insertionIndex = unwrappedJson.range(of: search, options: .backwards)?.lowerBound {
-                let definitions = try JSONEncodeDefinitions(pretty: encoder.outputFormatting == .prettyPrinted)
+                let definitions = try JSONEncodeDefinitions(pretty: encoder.outputFormatting.contains(.prettyPrinted))
                 unwrappedJson.replaceSubrange(insertionIndex..., with: definitions)
             }
             json = unwrappedJson

        let nl = pretty ? "\n" : ""

        let encoder = JSONEncoder()
        var fieldCount = 1
        for (field, fieldProps) in properties {
            propertyStr.append("\(sp)\"\(field)\": ")

            contentStr.append("\(sp)\"type\": \"\(modelRef.type)\",\(nl)")
            if modelRef.required.count > 0 {
                let encoder = JSONEncoder()
                if #available(OSX 10.13, *) {
                    encoder.outputFormatting = .sortedKeys
                } else {
                    // Fallback on earlier versions
                }
                do {
                    let encodedData = try encoder.encode(modelRef.required.sorted())
                    if let json = String(data: encodedData, encoding: .utf8) {
                        contentStr.append("\(sp)\"required\": \(json),\(nl)")
                    } else {
