ChetanBhasin
11/29/2018 - 9:26 PM

JSON Stringify in Swift 4

JSON Stringify in Swift 4

func jsonStringify(value: JSON) -> String {
    let returnable = ""
    
    if let data = try? JSONSerialization.data(withJSONObject: value, options: JSONSerialization.WritingOptions.sortedKeys) {
        if let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) {
            return string as String
        }
    }
    
    return returnable
}