Skip to content

New flag JSON_DECODE_BIGINT_AS_REAL #698

@mjh-c

Description

@mjh-c

We encountered a use case where we received a very large integer within a JSON payload in a REST call. From the (OpenAPI) schema point of view, the value is of real type in fact, but the JSON serializer on client side decided to send it as a large integer value.
In the concrete case, a real value 1.7E19 was added as 17000000000000000000 to the JSON payload. This integer is too big to fit into the integer type json_int_t.
jansson does not accept that and returns "too big integer near '17000000000000000000'".

Using the decoder flag JSON_DECODE_INT_AS_REAL is not an option, since the payload also contains large integers that fit into json_int_t (64-bit ID values, for example) and they would be silently modified by rounding which would break the whole application.

The idea is to introduce a new decoder flag JSON_DECODE_BIGINT_AS_REAL that works similar to JSON_DECODE_INT_AS_REAL but only converts too big integers to real type and leaves integers that fit into json_int_t unmodified. This would perfectly satisfy our needs. Bringing in this new decoder flag is non-intrusive and would leave the old behavior completely unchanged.

I already prepared a branch and will create a PR for review if you don't mind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions