Skip to content

Preserve integer precision and object key order in fromjson #19

Closed

Description

@qoke

fromjson can lose precision when decoding large integer tokens. It can also lose object key order when decoding through unordered Go maps.

Both show up when reading JSON configuration:

{% set config = '{"id":9007199254740993}' | fromjson %}
{{ config.id }}
{% for name in '{"upf":1,"amf":2}' | fromjson %}{{ name }};{% endfor %}

Expected rendered values:

9007199254740993
upf;amf;

I’m putting together a PR that retains numeric tokens as json.Number until their type is determined and builds ordered dictionaries from the input. The same handling applies to nested objects and arrays.

The decoder will also check for trailing data after the first complete JSON value and return parsing errors with context.

I’ll link the PR here with regression tests for integer precision and key order. For the Python reference, fromjson is registered using json.loads, since it isn’t a built-in Jinja2 filter. Integer preservation remains limited to the Go engine’s supported range.

Activity

  1. ardan-bkennedy commented on Oct 26, 2026

    @ardan-bkennedy
    Contributor

    Resolved in #34 and published in v1.11.0, with corresponding regression tests covering the reported problem. Thank you, @qoke, for the report and suggested solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions