← index #16963PR #6838
Related · high · value 2.531
QUERY · ISSUE

suggestion: json.dump() does not support default keyword argument

openby xuancong84opened 2025-03-20updated 2025-03-20
enhancement

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

CANDIDATE · PULL REQUEST

extmod/modujson: Support specifying separators in dump()

closedby peterzugeropened 2021-02-03updated 2021-06-22
extmod

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied