Skip to content

Commit 07ff207

Browse files
authored
fix: apply filtering when walking json arrays (#1086)
1 parent f802828 commit 07ff207

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.changeset/shaggy-apes-call.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/smithy-client": patch
3+
---
4+
5+
apply json default filtering when walking through arrays

packages/smithy-client/src/serde-json.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,17 @@ describe(_json.name, () => {
3636
a: { b: 5, c: [6] },
3737
});
3838
});
39+
40+
it("recursively removes nullish entries in arrays", () => {
41+
expect(
42+
_json({
43+
a: {
44+
b: 5,
45+
c: [, , { a: 5, b: 6, c: null, d: undefined }, 6],
46+
},
47+
})
48+
).toEqual({
49+
a: { b: 5, c: [{ a: 5, b: 6 }, 6] },
50+
});
51+
});
3952
});

packages/smithy-client/src/serde-json.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const _json = (obj: any): any => {
1212
return {};
1313
}
1414
if (Array.isArray(obj)) {
15-
return obj.filter((_: any) => _ != null);
15+
return obj.filter((_: any) => _ != null).map(_json);
1616
}
1717
if (typeof obj === "object") {
1818
const target: any = {};

0 commit comments

Comments
 (0)