Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Why decimal? #30

Description

@ivoras

I've noticed that django-json-field treats my floating point data as Decimal type. I've seen why you did it by looking at the issues history of the project on GitHub, but I think it's really inconvenient, here's why:

  • Python's default fast JSON encoder (json.dumps) written in C chokes when I give it data I got from a JSONField field (as a part of a larger structure), forcing me to use a custom encoder in Python, which is orders of magnitude slower.
  • Decimal data type itself is hugely slower than float
  • All modern browsers treat the JavaScript "number" type internally as a double precision float, so the added precision of Decimal is lost when transferred to the browser. JSON is not JavaScript, but you must admit it's most commonly used as such.

Could you make an option to be used in the field declaration to treat floats as floats? E.g.
f = JSONField(null=True, pure_float=True)

... or something like it?

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions