title: json.dumps on dictionary with bytes for keys
body: <p>Trying to convert dictionary object with keys of type bytes to json using json.dumps(). Format of dictionary object is not known beforehand. Have found solution for arrays or dictionaries with byte values when using json.dumps (<a href="https://stackoverflow.com/questions/56874045/convert-bytes-embedded-in-list-or-dict-to-str-for-use-with-json-dumps">Convert bytes embedded in list (or dict) to str for use with json.dumps</a>) but have not found one for byte keys.</p>
  
  <pre><code>import json
  
  class BytesDump(json.JSONEncoder):
      def default(self, obj):
          if isinstance(obj, bytes):
              return obj.decode()
          return json.JSONEncoder.default(self, obj)
  
  foo = {'name': b'bob', 'age': 33, 'attributes': {'hair': b'brown', 'arms': 2}}
  bar = {b'name': b'bob', b'age': 33, b'attributes': {b'hair': b'brown', b'arms': 2}}
  
  print(json.dumps(foo, cls=BytesDump)) # this works
  print(json.dumps(bar, cls=BytesDump)) # this doesn't work
  </code></pre>
  
  <p>Output  from above</p>
  
  <pre><code>{"name": "bob", "age": 33, "attributes": {"hair": "brown", "arms": 2}}
  Traceback (most recent call last):
    File "./test.py", line 15, in &lt;module&gt;
      print(json.dumps(bar, cls=BytesDump))
    File "/usr/local/lib/python3.6/json/__init__.py", line 238, in dumps
      **kw).encode(obj)
    File "/usr/local/lib/python3.6/json/encoder.py", line 199, in encode
      chunks = self.iterencode(o, _one_shot=True)
    File "/usr/local/lib/python3.6/json/encoder.py", line 257, in iterencode
      return _iterencode(o, 0)
  TypeError: keys must be a string
  </code></pre>