I am not sure `(str(o),)` is what I want. For a comparison here are three 
examples:
```
json:orig = {"val": 0.6441726684570313}
json:pyth = {'val': 0.6441726684570312}
json:seri = {"val": 0.6441726684570312}

dson:orig = {"val": 0.6441726684570313}
dson:pyth = {'val': Decimal('0.6441726684570313')}
dson:seri = {"val": ["0.6441726684570313"]}

sjson:orig = {"val": 0.6441726684570313}
sjson:pyth = {'val': Decimal('0.6441726684570313')}
sjson:seri = {"val": 0.6441726684570313}
```
Each one has three outputs, `orig` is the input text, `pyth` is its python 
representation in a `dict`, `seri` is the serialized text output of `pyth`.

Now, the prefixes are `json` for standard Python module (which gets the last 
digit different from the output). `dson` is standard Python module using 
`parse_float=decimal.Decimal` on `json.loads` and custom serializer with 
proposed `return (str(o),)`. Finally `sjson` is `simplejson` using 
`use_decimal=True` on `json.loads` and the same (which is default) on its 
`json.dumps`.

When I had `return str(o)` in the custom impl. I ended up with the string in 
the output:
```
dson:orig = {"val": 0.6441726684570313}
dson:pyth = {'val': Decimal('0.6441726684570313')}
dson:seri = {"val": "0.6441726684570313"}
```
and finally, with `return float(o)` I am basically back at the square one:
```
dson:orig = {"val": 0.6441726684570313}
dson:pyth = {'val': Decimal('0.6441726684570313')}
dson:seri = {"val": 0.6441726684570312}
```
The possibility to specify the "raw" textual output, which does not get mangled 
by the JSONEncoder when custom encoder is used seems to be missing.
˙``
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5JKBNFEH242GCB2JHNDPVA4ACY2TWU23/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to