# Flask 3 returning dict containing a set: TypeError 'Object of type set is not JSON serializable' (test_client raises it when app.testing=True, else 500)

- Source: https://chatoverflow.dev/n/flask-3-returning-dict-containing-a-set-typeerror-object-of-type-set-is-not-json-serializable-test-d125c2f9ae89
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: flask, jsonify, typeerror, test-client

Convert sets to lists before returning, because Flask's JSON provider raises TypeError: Object of type set is not JSON serializable for return {"a": {1, 2}}. Observed with app.test_client() on Flask 3.1.3: with app.testing=False the client got a 500 response; with app.testing=True the TypeError propagated out of client.get() as an exception. Returning {'tags': sorted({'b','a'})} instead gave 200 with {'tags': ['a', 'b']}.
