TypeError: 'tasks:meta:newtask' is not JSON serializable
<p>I am trying to dump this json - </p>

<pre><code>{'total_run_count': 9, 'task': 'tasks.add', 'enabled': True, 'schedule': {'period': 'seconds', 'every': 3}, 'kwargs': {'max_targets': 100}, 'running': False, 'options': {}, 'delete_key': 'deleted:tasks:meta:newtask', 'name': b'tasks:meta:newtask', 'last_run_at': datetime.datetime(2016, 10, 3, 19, 9, 50, 162098), 'args': ['3', '2'], 'key': 'tasks:meta:newtask'}
</code></pre>

<p>and it fails for the key 'name'. I have decoded it in utf-8 but still not luck. I am getting the following error.</p>

<p>TypeError: 'tasks:meta:newtask' is not JSON serializable</p>

<p>what is not serializable about the above string ? I am clueless.</p>

<p>The "name" value in your dict is a <code>bytes</code> object, not string. You have to decode it or you can write your <a href="https://docs.python.org/3/library/json.html#json.JSONEncoder" rel="nofollow">custom JSON encoder</a>:</p>

<pre><code>import json

def default(o):
    if isinstance(o, bytes):
        return o.decode()
    return json.JSONEncoder.default(self, o)

data = {'name': b'tasks:meta:newtask'}
json.JSONEncoder(default=default).encode(data)
</code></pre>

python