suggestion: json.dump() does not support default keyword argument
Description
In the standard Python3 JSON library (https://docs.python.org/3/library/json.html), json.dump() or json.dumps() support the default keyword argument which specifies how to serialize non-standard data types.
default (callable | None) – A function that is called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError. If None (the default), TypeError is raised.
Currently, this is not implemented:
>>> json.dumps({}, default=None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: extra keyword arguments given
I think this will be a useful addition. Thanks!
Code Size
No response
Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree
extmod/modujson: Support specifying separators in dump()
This PR adds support for the separators keyword argument in
ujson.dump() and ujson.dumps().
Additionally added the keyword argument indent which is only
allowed to be None and raises NotImplementedError
otherwise. This was added because the arguments is connected to
the separators argument.
This PR is currently implemented reentrant to support calling
json.dump/s in an interrupt. Since allocation (and in turn
json.dump/s) is not available in ISR's this could be removed to
simplify the implementation slightly.