Created
February 9, 2017 12:45
-
-
Save Edudjr/cbd09220de89679f25eced359a6b8e08 to your computer and use it in GitHub Desktop.
Swift 3 JSON pretty printing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Function to pretty-print Json Object in Swift 3 | |
func prettyPrint(with json: [String:Any]) -> String{ | |
let data = try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) | |
let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) | |
return string as! String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to Pure Swift:
Usage:
Output: