python-fastjsonschema icon indicating copy to clipboard operation
python-fastjsonschema copied to clipboard

Support Decimals as numbers

Open Lexicality opened this issue 3 years ago • 0 comments

I have a schema like this:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "orderValue": {
            "type": "number",
            "minimum": 0
        },
        "commission": {
            "type": "number",
            "minimum": 0
        }
    }
}

and data like this:

{
    "orderValue": 49.5452999999998,
    "commission": 8.334900000001
}

and I would like to parse it like this:

data = json.loads(raw_data, parse_float=decimal.Decimal)

to try and avoid losing any more precision to floating points, however when I feed data into the schema validation it gives me the error

fastjsonschema.exceptions.JsonSchemaValueException: data.orderValue must be number

Is there a way I can have Decimals treated like numbers?

Lexicality avatar Jul 06 '21 17:07 Lexicality