Decimals
There is a popular JSON-using program out there (Bitcoin) which uses JSON reals for decimal values. Specifically, there are always exactly 8 digits of precision in its values, all of which need to be preserved. This PR supports that usecase by adding a JSON_READ_DECIMALS flag to json_loads(), which causes all numbers to be parsed as the new json_decimal type (rather than integers or reals).
Internally, json_decimals are just an integer alongside a decimal-position value which represents the number of digits after the decimal point.
So decimal is just a fixed-point number that has to fit the 31 or 63 bits that json_int_t has to offer? The usefulness sounds quite limited to me. Regular IEEE 754 double is able to represent numbers up to 53 bits of precision, so I don't see a huge advantage there.
The bignum hooks patch by Deron Meranda provide a more flexible approach. You could even implement your decimals using them. See http://deron.meranda.us/computing/c/jansson-bignum/. It just needs rebasing on top of current master and finishing the work.
Thanks for your comment. IEEE754 can't represent any decimal digits because it is a binary-point format (eg famously 0.1 cannot be represented precisely). In particular I was seeing wrong values output pretty consistently when dealing with the 8-decimal-place values which the bitcoin software gives me.
I certainly agree that this would be much more useful built on top of bignums. For my application the limited range was more than enough because with 63 bits I can still represent numbers up to 92000 million or so with 8 decimal places. (With 31 bits I can get up to 20, which is actually still a useful amount for my purposes.)
So if you want to close this on that basis that seems reasonable. But bear in mind that this code is working today. I'm interested in redoing this on top of bignums but I can't say when I'll have the spare cycles to do so.
I rebased the original bignum patch by @dmeranda on top of current master:
https://github.com/akheron/jansson/tree/bignum
If you have time, you could have a look at it and how well it works for your use case.