Support non-'decimal.Decimal' output

Bug #320555 reported by alecf
2
Affects Status Importance Assigned to Milestone
jsonlib
Fix Released
Wishlist
John Millikin

Bug Description

Since decimal.Decimal numbers can't be compared directly with python floats, it would be really nice if jsonlib could produce regular floats. I realize there's some lack of accuracy because python floats are kinda funky, but for my application, floats make way more sense..

I'm attaching a patch that adds 'use_float=False' as a default parameter to load/read

Revision history for this message
alecf (alecf) wrote :
Revision history for this message
John Millikin (jmillikin) wrote :

I would prefer not to add such an option, for two reasons:

* Floating-point inaccuracy causes silent data loss.
* Round-tripping with floats can change values: write(read('[1.4]', use_float=True)) -> '[1.3999999999999999]'

Are these drawbacks acceptable to you?

In addition, please note that jsonlib was developed before Python had a standardized JSON library. Since then, simplejson[1] has been adopted into the standard library for 2.6 and 3.0. If possible, it would be best to use a library that will be more familiar to potential maintainers of your code. I will continue to maintain jsonlib, but it is unlikely to see major further development.

[1] http://pypi.python.org/pypi/simplejson/

Changed in jsonlib:
assignee: nobody → jmillikin
importance: Undecided → Wishlist
Revision history for this message
alecf (alecf) wrote : Re: [Bug 320555] Re: Support non-'decimal.Decimal' output

They are acceptable tradeoffs - it's how simplejson has always behaved,
which is what we've been using (since simplejson 1.0!). Over at
freebase.comwe have a RESTful json-based API and we're finding for
large datastructures,
we get a very noticeable performance boost with jsonlib. jsonlib is the
only viable c-based json library that we've found!
In the long run decimal is probably where we want to go with our own
codebase, but that codebase is much larger than jsonlib, and we've survived
2 1/2 years with floats without too much criticism/confusion from our users
:)

if you're not interested in maintaining jsonlib, I'm happy to help... I'd
like to avoid forking, which is why I'm submitting patches. One way or
another we'll have to run with this patch internally, but I'm sure I'm not
the only one interested in float.

Revision history for this message
John Millikin (jmillikin) wrote :

OK, as long as the downsides to floats are understood. New release, 1.3.10, for this feature now available.

I'm very happy to hear jsonlib is useful to you.

Changed in jsonlib:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.