Skip to content

Preserve array indexes when serializing query results - #443

Open
nk-batman21 wants to merge 1 commit into
antonmedv:masterfrom
nk-batman21:fix-array-stringify-indexes
Open

nk-batman21 wants to merge 1 commit into
antonmedv:masterfrom
nk-batman21:fix-array-stringify-indexes

Conversation

@nk-batman21

Copy link
Copy Markdown

Deleting an array element in a query changes later indexes in the JSON output:

printf '[1,2,3]' | fx 'x => { delete x[1]; return x }'

This currently produces [1,3] instead of [1,null,3]. The serializer enumerates the array's own keys, so holes disappear, non-enumerable indexes are omitted, and extra named properties become array elements.

Serialize indexes from zero to the array's length and write missing values as null. This fixes both compact query output and the indented serializer used by save(). Tests compare five affected arrays against JSON.stringify in both modes.

Validation: all five cases fail on the unchanged base. The full Go suite passes on Linux; the engine suite, go vet ./internal/engine, and a built CLI reproduction pass on Windows.

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