Skip to content

Support int64 and int32 in Marshal - #344

Closed
draarivpatel-ui wants to merge 1 commit into
itchyny:mainfrom
draarivpatel-ui:fix-marshal-int64-int32
Closed

draarivpatel-ui wants to merge 1 commit into
itchyny:mainfrom
draarivpatel-ui:fix-marshal-int64-int32

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Problem

gojq.Marshal panics with invalid type: int64 (3) when the value
contains integers typed int64 or int32. Such values are common when
gojq is used as a library on data decoded by Kubernetes-aware JSON
libraries (sigs.k8s.io/json.UnmarshalCaseSensitivePreserveInts
decodes integral numbers as int64, and even on 64-bit platforms
int and int64 are distinct Go types), so encoding results back to
JSON crashes the process.

Fix

Handle int64 and int32 in the encoder's type switch, exactly like
the existing int case, and extend the documented list of accepted
types accordingly.

A regression test covers plain and nested int64/int32 values; it
panics without the fix and passes with it. The full package test suite
passes.

Fixes #294

The encoder panicked with "invalid type: int64" for values typed
int64 or int32, which occur in data deserialized by Kubernetes-aware
JSON libraries (sigs.k8s.io/json uses int64 for integral numbers).
Handle them like int in the type switch.

Fixes itchyny#294
Copilot AI balanced review requested due to automatic review settings November 25, 2026 16:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@itchyny

itchyny commented Nov 25, 2026

Copy link
Copy Markdown
Owner

gojq does not support processing int64/int32.

@itchyny itchyny closed this Nov 25, 2026
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

Successfully merging this pull request may close these issues.

3 participants