Skip to content

Instantly share code, notes, and snippets.

@shaps80
Created January 5, 2021 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shaps80/ec693d67ad0b6d420dfc450fc82d7b05 to your computer and use it in GitHub Desktop.
Save shaps80/ec693d67ad0b6d420dfc450fc82d7b05 to your computer and use it in GitHub Desktop.
extension Encodable {
var debugJson: String {
(try? JSONEncoder().encode(self).debugJson) ?? ""
}
}
extension Data {
var debugJson: String {
String(decoding: self, as: UTF8.self)
}
}
/*
Demo:
struct Name: Encodable {
var first: String
var last: String
}
print(Name(first: "Shaps", last: "Benkau").debugJson)
// { "first": "Shaps", "last": "Benkau" }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment