Skip to content

Conversation

eaglethrost
Copy link
Contributor

🚥 Resolves ISSUE_ID

🧰 Changes

  • This PR is part of the work for the readme ticket RM-9906 Not displaying null values in an array and should get merged first before the changes in the oas repo
  • Removes the JSON.parse(stringify) code in favour implementing own function to remove undefined objects so that undefined values don't get converted to nulls, allowing us to separate user added nulls
  • In addition, don't remove null values in arrays when stripping objects. I think this is fine todo because from my understanding that code was just to removed the null-converted undefined, please let me know if I'm wrong. Open to feedback on how to approach this.

🧬 QA & Testing

  • To the removeUndefinedObjects function, pass in an array with nulls and they should get retained
  • Primitive nulls should get retained, undefined should still get filtered

expect(removeUndefinedObjects(obj)).toStrictEqual({
d: [1234],
f: null,
g: [null, null],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this appearing now?

@erunion erunion requested a review from kanadgupta September 10, 2025 16:47
@erunion erunion added the enhancement New feature or request label Sep 10, 2025
Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i guess i'll defer to @erunion on the expected default behavior here — should null values be filtered out of arrays by default? or should we add an add'l option for this?

i do agree that the current JSON.parse(JSON.stringify(obj)) behavior does occasionally yield unexpected results (which we kinda sorta account for):

Image

@erunion
Copy link
Member

erunion commented Sep 10, 2025

Yea I just want to make sure there aren't any regressions from how this library behaves currently as we use it in a number of areas within the application.

@eaglethrost
Copy link
Contributor Author

eaglethrost commented Sep 10, 2025

Yea I just want to make sure there aren't any regressions from how this library behaves currently as we use it in a number of areas within the application.

Yeah that was my concern as well and why I thought about cloning the functionality to the oas repo. To reduce the chance of regression, I agree with Kanad's approach on creating an optional option to preserve nulls. Setting the option on would use the custom remove undefined objects function, instead of stringifying, and not removing nulls in array. This will be set in oas-to-har only for now and other parts of the app that use this package should be unaffected. Do you agree? @erunion

Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok after giving it a further think through, i think this is technically fixing unexpected behavior and i'm ok with updating the default behavior as opposed to introducing another flag? based on the README, it looks like we are NOT supposed to remove null values:

Image

i do share @erunion's concerns for regressions though, will defer to him on the final call!

README.md Outdated
```js
import removeUndefinedObjects from 'remove-undefined-objects';

console.log(removeUndefinedObjects({ key1: [null, undefined], key2: 123 }, { preserveArrayNulls: true }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add another example that's using the exact same object but with preserveArrayNulls set to false so it illustrates the difference?

@eaglethrost eaglethrost requested a review from erunion September 11, 2025 00:32
@eaglethrost
Copy link
Contributor Author

Update: Changed current approach to put preserving array nulls under an optional flag to reduce chances of regression. Happy to revert it back to make it the default behaviour as kanad pointed out.

@erunion erunion requested a review from kanadgupta September 11, 2025 15:33
Copy link
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple minor things but overall im happy with this

@eaglethrost eaglethrost requested a review from erunion September 11, 2025 20:38
Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one final request otherwise LGTM!

@erunion erunion merged commit 34f3cc2 into readmeio:main Sep 12, 2025
5 checks passed
@erunion
Copy link
Member

erunion commented Sep 12, 2025

Published to v7.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants