@@ -71,7 +71,8 @@ import Foundation
7171
7272 // MARK: - Initializers
7373
74- /// Create JSON from raw `Data`
74+ /// Create JSON from raw `Data`.
75+ ///
7576 /// - Parameters:
7677 /// - data: Raw `Data` of JSON object
7778 /// - options: Optional serialization options
@@ -90,8 +91,9 @@ import Foundation
9091 /// - model: `Encodable` model
9192 /// - encoder: Encoder for encoding the model
9293 public init ( encodable model: any Encodable , encoder: JSONEncoder ) {
93- if let data = try ? encoder. encode ( model) , let converted = try ? JSON ( data: data) {
94- self = converted
94+ if let data = try ? encoder. encode ( model) ,
95+ let jsonData = try ? JSON ( data: data) {
96+ self = jsonData
9597 } else {
9698 self = JSON . null
9799 }
@@ -105,20 +107,20 @@ import Foundation
105107 ///
106108 /// - Parameter object: Object to try to represent as JSON
107109 public init ( _ object: Any ) {
108- if let data = object as? Data , let converted = try ? JSON ( data: data) {
109- self = converted
110- } else if let model = object as? any Encodable , let data = try ? JSONEncoder ( ) . encode ( model) , let converted = try ? JSON ( data: data) {
111- self = converted
110+ if let data = object as? Data , let jsonData = try ? JSON ( data: data) {
111+ self = jsonData
112+ } else if let model = object as? any Encodable , let data = try ? JSONEncoder ( ) . encode ( model) , let jsonData = try ? JSON ( data: data) {
113+ self = jsonData
112114 } else if let dictionary = object as? [ String : Any ] {
113115 self = JSON . dictionary ( dictionary. mapValues { JSON ( $0) } )
114116 } else if let array = object as? [ Any ] {
115117 self = JSON . array ( array. map { JSON ( $0) } )
116118 } else if let string = object as? String {
117119 self = JSON . string ( string)
118- } else if let bool = object as? Bool {
119- self = JSON . bool ( bool)
120120 } else if let number = object as? NSNumber {
121121 self = JSON . number ( number)
122+ } else if let bool = object as? Bool {
123+ self = JSON . bool ( bool)
122124 } else if let json = object as? JSON {
123125 self = json
124126 } else {
0 commit comments