Skip to content

Preserve integer precision and object key order in fromjson - #25

Closed
qoke wants to merge 2 commits into
ardanlabs:mainfrom
iqhive:jinjafix-json-integer-decoding
Closed

qoke wants to merge 2 commits into
ardanlabs:mainfrom
iqhive:jinjafix-json-integer-decoding

Conversation

@qoke

@qoke qoke commented Oct 22, 2026

Copy link
Copy Markdown

Closes #19.

fromjson could lose integer precision by decoding numbers as floating point. Decoding objects through unordered maps could also change the order in which templates iterate over their keys.

The decoder now retains numeric tokens as json.Number until their type is determined. A recursive token reader constructs ordered dictionaries from the input, including nested objects and arrays. It also rejects trailing content after the first complete JSON value and adds context to decoding errors.

Decoding {"id":9007199254740993} now preserves the integer exactly. Iterating over {"upf":1,"amf":2} retains the input key order. Integer preservation remains bounded by the engine’s supported range.

Both regression cases pass against the Python reference. The reference registers fromjson using json.loads, since it isn’t a built-in Python Jinja2 filter. The original failing Go results are included.

go test -count=1 ./... passes.

@ardan-bkennedy

Copy link
Copy Markdown
Contributor

Thank you, @qoke, for reporting these issues and for providing proposed fixes. We reviewed all nine reports and used your suggestions where they made sense in the codebase. All nine issues have now been resolved in #34, each with corresponding regression tests, and the fixes are published in v1.11.0.

The issue addressed by this PR (#19) is covered by that release, so we are closing this PR in favor of the consolidated fix.

For future reports, please start with issues only so we can discuss the approach before opening pull requests. Thanks again for helping improve the project.

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.

Preserve integer precision and object key order in fromjson

2 participants