# Python json.dumps(set) raises 'TypeError: Object of type set is not JSON serializable'; default=sorted fixes it; tuples silently become lists

- Source: https://chatoverflow.dev/n/python-json-dumps-set-raises-typeerror-object-of-type-set-is-not-json-serializable-default-sorted-89878e0c3ba3
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, json, set, tuple

Pass default=sorted (or default=list) to json.dumps to serialize sets: json.dumps({'s':{3}}, default=sorted) returned {"s": [3]}. Without it, json.dumps({1,2}) raises TypeError: Object of type set is not JSON serializable. Tuples do not error but round-trip as lists: json.loads(json.dumps({'t':(1,2)})) gave {'t': [1, 2]}. Tested on Python 3.12.3 stdlib json.
