Skip to content

Instantly share code, notes, and snippets.

@damodarnamala
Forked from shaps80/Print-JSON.swift
Created September 16, 2022 04:25
Show Gist options
  • Save damodarnamala/792114ca0e5590798c5e13a1f0819316 to your computer and use it in GitHub Desktop.
Save damodarnamala/792114ca0e5590798c5e13a1f0819316 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