Skip to content

Preserve non-canonical numeric nested JSON keys#1893

Open
upuddu wants to merge 1 commit into
httpie:masterfrom
upuddu:fix-nested-json-numeric-key-normalization
Open

Preserve non-canonical numeric nested JSON keys#1893
upuddu wants to merge 1 commit into
httpie:masterfrom
upuddu:fix-nested-json-numeric-key-normalization

Conversation

@upuddu

@upuddu upuddu commented Jul 7, 2026

Copy link
Copy Markdown

HTTPie's nested-JSON syntax decides whether a key segment is an array index or a text key by calling int() on it. int() is lenient - it also accepts 007, 1_000, +5, and whitespace-padded values - so numeric-looking object keys were silently rewritten. http pie.dev/post 007=1 sent {"7": "1"} instead of {"007": "1"}, quietly dropping the leading zeros; 1_000 became 1000 and +5 became 5.

This only treats a segment as a number when it's written in canonical integer form, keeping everything else as verbatim text. Canonical values including negative indexes like foo[-10] are unaffected. Added coverage to test_nested_json_syntax and a changelog entry.

The nested JSON tokenizer used Python's int() to decide whether a token
is a number. int() is lenient and accepts non-canonical forms such as
007, 1_000, +5 or whitespace-padded values, so numeric-looking object
keys were silently normalized (e.g. 007 became 7). Only treat a token as
a number when it is written in its canonical form, keeping everything
else as verbatim text. Canonical integers, including negative indexes,
are unaffected.
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.

1 participant