Great small improvement ideas @beccadax! Love them all.
I think that's pretty good actually, +1.
If someone wanted to force the "dumpToDisk": {}
anyway it's possible without manually en/decoding, by declaring:
case dumpToDisk(Empty)
struct Empty {}
I guess, which is a simple and natural enough workaround if someone needs this.
That's actually fine even in toplevel and we fixed this recently ( [5.2] SR-12275: JSONEncoder on Linux can't encode number JSON fragments by ktoso · Pull Request #2840 · apple/swift-corelibs-foundation · GitHub backport PR to 5.2, works fine on 5.3 ):
3> String(data: JSONEncoder().encode("hello"), encoding: .utf8)
$R1: String? = "\"hello\""
(related thread Allowing top-level fragments in JSONDecoder )