Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New flag JSON_DECODE_BIGINT_AS_REAL #698

Open
mjh-c opened this issue Sep 24, 2024 · 0 comments
Open

New flag JSON_DECODE_BIGINT_AS_REAL #698

mjh-c opened this issue Sep 24, 2024 · 0 comments

Comments

@mjh-c
Copy link

mjh-c commented Sep 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant