Skip to content

Instantly share code, notes, and snippets.

@deffjay
Last active September 30, 2019 19:25
Show Gist options
  • Save deffjay/6e0de6bb767b8c0533049541a48b91bd to your computer and use it in GitHub Desktop.
Save deffjay/6e0de6bb767b8c0533049541a48b91bd to your computer and use it in GitHub Desktop.
Pretty print JSON from an object in Swift5
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