fix: std.parseJson handles integers outside Java long range#1019
Merged
stephenamar-db merged 1 commit intoJun 24, 2026
Conversation
Motivation:
std.parseJson crashed with NumberFormatException when parsing JSON
integers that exceed Java long range ([-2^63, 2^63-1]). C++ jsonnet,
go-jsonnet, and jrsonnet all gracefully parse them as float64.
Modification:
- ValVisitor.scala: Catch NumberFormatException from
parseIntegralNum and fall back to Double.parseDouble, which
handles arbitrarily large integers with float64 precision.
Result:
std.parseJson("9223372036854775808") now returns a float64 value
instead of crashing.
Cross-implementation comparison:
| Expression | cpp-jsonnet | go-jsonnet | jrsonnet | sjsonnet (before) | sjsonnet (after) |
|---|---|---|---|---|---|
| parseJson("2^63") | 9223372036854775808 | 9223372036854775808 | 9.22e+18 | CRASH ❌ | 9.22e+18 ✅ |
| parseJson("-2^63-1") | -9223372036854775808 | -9223372036854775808 | -9.22e+18 | CRASH ❌ | -9.22e+18 ✅ |
| parseJson("10^31") | 10^31 (float) | 10^31 (float) | 10^31 (float) | CRASH ❌ | 10^31 (float) ✅ |
| parseJson("42") | 42 | 42 | 42 | 42 ✅ | 42 ✅ |
stephenamar-db
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: std.parseJson handles integers outside Java long range
Motivation
std.parseJsoncrashed withNumberFormatExceptionwhen parsing JSON integers exceeding Javalongrange ([-2^63, 2^63-1]). C++ jsonnet, go-jsonnet, and jrsonnet all gracefully parse them as float64.Modification
ValVisitor.scala: CatchNumberFormatExceptionfromparseIntegralNuminvisitFloat64StringParts, falling back toDouble.parseDouble.parsejson_large_integer.jsonnetResult
Large integers no longer crash; they degrade to float64.
parseJson("2^63")9.22e+189.22e+189.22e+189.22e+18✅parseJson("-2^63-1")-9.22e+18-9.22e+18-9.22e+18-9.22e+18✅parseJson("42")42424242✅42✅