Last active
September 30, 2019 19:25
-
-
Save deffjay/6e0de6bb767b8c0533049541a48b91bd to your computer and use it in GitHub Desktop.
Pretty print JSON from an object in Swift5
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
do { | |
let jsonEncoder = JSONEncoder() | |
jsonEncoder.outputFormatting = .prettyPrinted | |
let jsonData = try jsonEncoder.encode(palettes) | |
if let jsonString = String(data: jsonData, encoding: .utf8) { | |
print(jsonString) | |
} | |
} catch { | |
print("error") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment