Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply filtering when walking json arrays #1086

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shaggy-apes-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/smithy-client": patch
---

apply json default filtering when walking through arrays
13 changes: 13 additions & 0 deletions packages/smithy-client/src/serde-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ describe(_json.name, () => {
a: { b: 5, c: [6] },
});
});

it("recursively removes nullish entries in arrays", () => {
expect(
_json({
a: {
b: 5,
c: [, , { a: 5, b: 6, c: null, d: undefined }, 6],
},
})
).toEqual({
a: { b: 5, c: [{ a: 5, b: 6 }, 6] },
});
});
});
2 changes: 1 addition & 1 deletion packages/smithy-client/src/serde-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const _json = (obj: any): any => {
return {};
}
if (Array.isArray(obj)) {
return obj.filter((_: any) => _ != null);
return obj.filter((_: any) => _ != null).map(_json);
}
if (typeof obj === "object") {
const target: any = {};
Expand Down
Loading