In the decimal vs float question for money in JSON, decimal wins. A float stores amounts in binary, so values like 0.10 are approximations and column totals drift by fractions of a cent. Send tax amounts as decimal strings such as "1250.10" or as integer cents, and parse them into a decimal type, never a float.
Why does a float break money in JSON?
A float breaks money in JSON because binary floating point cannot store most decimal fractions exactly. The number 0.1 becomes the closest binary value, which is slightly off. One amount looks fine on screen, but sums, comparisons and rounding over a column of amounts expose the error.
The Python tutorial on floating-point arithmetic states that the decimal value 0.1 cannot be represented exactly as a base 2 fraction, and calls this "the very nature of binary floating point". JavaScript has the same limit. The MDN reference for the Number type says a JavaScript Number is a double-precision 64-bit binary IEEE 754 value.
JSON itself does not say how a reader stores a number. RFC 8259, the JSON specification, says good interoperability comes from implementations that expect no more precision than IEEE 754 double precision provides, and that implementations will approximate JSON numbers within that precision. In practice, a JSON number like 1250.10 lands in a float in most default parsers.
These short snippets show the error. Both are runnable as written.
# Python: float drift
print(0.1 + 0.2) # 0.30000000000000004
print(sum([0.1] * 10)) # 0.9999999999999999
print(0.1 + 0.2 == 0.3) # False
// JavaScript: same drift
console.log(0.1 + 0.2); // 0.30000000000000004
console.log(0.1 + 0.2 === 0.3); // false
The second Python line is the one that matters for tax data. Ten amounts of ten cents should total one dollar. The float total is short by a tiny fraction. On a spreadsheet of 1099-INT interest amounts, that fraction can turn a check like "the total equals the sum of the rows" into a false failure, or round a total the wrong way at the cent.
Decimal strings or integer cents for money in JSON?
Decimal strings and integer cents both keep money exact in JSON. A decimal string such as "18400.00" keeps the amount readable and the precision explicit. Integer cents such as 1840000 keep it a number. For tax amounts, decimal strings are usually the clearer choice, because form boxes print dollars and cents.
Decimal strings
A decimal string is the amount written as text, with a fixed number of places. A fictional W-2 field might read "box_1_wages": "52340.17". Any language can read it into its decimal type without passing through a float. The cost is that a careless client can still call float() on it, and a string does not tell a schema validator it is a number unless the schema adds a pattern.
Integer cents
Integer cents store the amount as a whole number of the smallest unit: 5234017 for $52,340.17. Integers are exact in binary up to a limit. The MDN Number reference gives that limit as 2^53 - 1, exposed as Number.MAX_SAFE_INTEGER, which is about 90 trillion dollars in cents and far above any tax form amount. The cost is that every reader must know the field is in cents. A field named box_1_wages holding 5234017 is easy to misread as dollars.
Which suits tax amounts
Tax forms have a few traits that tip the balance. Some boxes allow negative values, some are blank rather than zero, and some amounts are whole dollars while others carry cents. A decimal string handles all of these: "-120.00", null and "350" are each unambiguous. Integer cents handle them too, but only if the unit is documented next to every field.
Whichever you pick, pick one per schema and name it. A field-naming rule such as a _cents suffix, or a schema note saying every amount is a two-place decimal string, prevents the mixed case where one field is dollars and another is cents. The guide to designing a tax form JSON schema covers where money fields sit and how to type them.
Parsing money in JSON from Python and JavaScript without floats
Parsing money in JSON without floats means the amount goes from JSON text straight to a decimal type. Python can do this with the standard library. JavaScript needs either strings in the JSON or a decimal library, because JSON.parse turns every JSON number into a Number before your code sees it.
Python
The Python json module documentation says the parse_float argument is called with the string of every JSON float, and that it can be used to parse floats into types such as decimal.Decimal. That one argument fixes JSON numbers. Decimal strings need a Decimal() call on the field.
import json
from decimal import Decimal, ROUND_HALF_UP
raw = '{"box_1_wages": 52340.17, "box_2_withheld": "6120.40"}' # example values
data = json.loads(raw, parse_float=Decimal)
wages = data["box_1_wages"] # Decimal('52340.17')
withheld = Decimal(data["box_2_withheld"]) # Decimal('6120.40')
print(sum([Decimal("0.1")] * 10)) # 1.0
print((wages * Decimal("0.062")).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP))
Two details from the Python decimal module documentation matter here. First, quantize() rounds to a fixed exponent, which the docs describe as useful for monetary applications. Second, building a Decimal from a float converts the exact binary value, so Decimal(1.1) becomes a long string of digits. Always build from the JSON string, never from a float you already parsed.
JavaScript
In JavaScript, the safest route is to receive amounts as strings and pass them to a decimal library. The decimal.js documentation describes it as an arbitrary-precision Decimal type for JavaScript, and its constructor accepts strings.
import Decimal from "decimal.js";
const data = JSON.parse('{"box_1_wages": "52340.17", "box_2_withheld": "6120.40"}'); // example values
const wages = new Decimal(data.box_1_wages);
const total = wages.plus(data.box_2_withheld);
console.log(total.toFixed(2)); // "58460.57"
If the API sends JSON numbers, newer runtimes offer a way out. The MDN reference for JSON.parse describes a reviver context argument whose source holds the original text of each primitive value, so you can rebuild the exact amount. Check the compatibility table for your runtime before relying on it.
Language-specific clients go further. The document extraction API guide for Python parses a full response into dataclasses with Decimal fields, and the document extraction API guide for Node JS adds a runtime schema check that rejects amounts sent as bare numbers.
When a float for money in JSON is acceptable
A float for money in JSON is acceptable when no one will add, compare or store the result as a record. Display-only charts, rough estimates and percentages shown to the nearest whole number can use floats safely, because an error in the sixteenth digit never reaches the screen or a total.
A chart of monthly income across a year is a fair example. The bar heights come from floats, and nobody reads a bar to the cent. A rough estimate, such as "about $2,400 in quarterly payments", is another: it is rounded before anyone sees it.
The line is crossed when the float flows back into a record. If a chart's data is later exported to a spreadsheet and summed, the drift returns. If an estimate is stored and compared against an actual figure from a form, the comparison can fail by a fraction of a cent. Keep the decimal value as the source and compute floats from it only at the point of display.
Extracted tax data almost never falls on the acceptable side. A value read from a W-2 or 1099 is a record of what a form says, and it will be summed, compared and exported. Schema Tax returns each box as a typed field with a fixed name and recomputes totals during validation, which is the step a float would break. The form-by-form list of supported fields shows which amounts each form carries. For exports to spreadsheets and CSV, where the same choice comes up again, see the Excel, CSV and JSON category.