Fix output of keys.

They need to be encoded in the same way that strings are
encoded.  (Report and fixed by Phil Roberts.)

Also added a FIXME about leftover occurrences of \U in the output.

Closes PR 13966.