Allow empty field names?


#1

Is there a reason to prohibit empty (quoted) record or union labels? I ran into this in Dhall for Java while writing some property-based round-trip tests where I had arbitrary JSON values that included objects with empty field names. I can easily filter these out, but I tried changing + to * in the equivalent of quoted-label there, and allowing empty labels doesn’t seem to break anything. Am I missing something?


#2

@travisbrown: There’s no particular reason why they are forbidden. We just never thought to permit them


#3

@Gabriel439 Thanks, I’ll go ahead and open a proposal PR then.


#4

And what about the backtick itself? It’s probably not widely used, but we should allow backticks too as JSON and YAML do. Maybe add an escaped

\`

in quoted-label-char ?


#5

I’m not sure parity with JSON or YAML field names should be the target here. The spec already explicitly prohibits non-printable-ASCII Unicode characters in labels, “mainly to minimize the potential for code obfuscation”, which seems like the right choice to me.

I guess you could argue that quoted labels should support all printable ASCII characters, and that it’s odd to exclude only the backtick, but I personally think the added complexity of supporting escapes outweighs that consideration (especially since \ is a valid character in quoted labels). Supporting empty quoted labels seems comparatively easy for implementations.


#6

(FWIW I’m more than happy to implement escaped backticks in Dhall for Java if there’s agreement that the spec should include them, and I do agree that there’s an argument on the basis of consistency. I just don’t think I’m convinced that the change is needed.)