How do I get jq to preserve bigint values? How do I get jq to preserve bigint values? json json

How do I get jq to preserve bigint values?


As of right now, the best jq has to offer with respect to JSON numbers is the "master" version, which preserves the external numerical value very well. The updates were made on or about 22 Oct 2019, and the "master" version of jq seems to be as safe to use as the most recent release (jq 1.6).

Examples using a recent "master" version:

    jqMaster -n -M '    [0000,     10000000000000000000000000000000000000012,      1.0000000000000000000000000000000000000012,      1000000000000000000000000000000000000001210000000000000000000000000000000000000012,     0.1e123456]'

Output

[  0,  10000000000000000000000000000000000000012,  1.0000000000000000000000000000000000000012,  1000000000000000000000000000000000000001210000000000000000000000000000000000000012,  1E+123455]


Another option would be to use “gojq”, the Go implementation of jq that uses unbounded-precision representation of integer literals.

In fact, except for one bug that has only been fixed in the “master” version of gojq as of this writing, gojq supports unbounded-precision integer arithmetic. The bug fix: https://github.com/itchyny/gojq/commit/7a1840289029c9c038d61274ceac9b8d307c0358