-
-
Save damodarnamala/792114ca0e5590798c5e13a1f0819316 to your computer and use it in GitHub Desktop.
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
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