I have, an an input, integers. I build a dict out of them (as values). I then dump it to JSON, to be reused elsewhere.
I ultimately (at the "elsewhere") need to use these integers as strings. I can therefore do the conversion
- upstream (when building the dict)
- or on the receiving side (the "elsewhere").
There will be, no matter the solution, plenty of str()
all over the code.
I am looking for a cleaner way to convert all the int
into str
in that specific case.
One idea is to recursively parse the dict once it is built, just before the json.dumps()
, and make the conversion there.
I am wondering, though, if there is not a way to handle this while dumping the JSON? Possibly with json.JSONEncoder? (which to be frank I do not understand much)