Plistlib and json modules have conflicting requirements for their dump
methods: Plistlib expects its file handle to be a writable binary file
object while json expects it to be a writable text file object.
This commit solves this issue by dumping the JSON into a temporary
string which is encoded to UTF-8 (JSON format RFC 7159 requires UTF-8,
UTF-16 or UTF-32 encoding and UTF-8 is the recommended default) before
being output. This allows to keep delegating file opening to Click and
avoid a refactoring to abstract the opening mode between supported
formats.
According to https://docs.python.org/3/library/json.html, the default argument for json.dumps's ensure_ascii parameter is true. I guess this means both Python 2 and Python 3 will behave the same here with encode(), so we're okay to just use that.