flattie
flattie copied to clipboard
Keep empty arrays and objects
Saw your new version last week and had to check if it could replace the one I've written. Among the test cases I've used is the Reddit JSON output, i.e.: https://www.reddit.com/r/cute.json
The one thing missing in flattie is keeping empty arrays or objects. I very much depend on the output to be reversible (unflatten(flatten(input)) deep equal to input), so I can't replace my implementation (yet).
Could keepNullish also keep other empty structures or could you change it to keepEmpty = <none, null, all>?
PS: Additional info about why I'm even flattening. I'm using a DB that holds JSON records, but only the first level can be indexed (i.e. no '.' inside the attribute selector). The API on-top does now transparent flattening/unflattening on write&read to make creating indexes easier. But consumers of the API would see the magic if empty structs are dropped.
Hey thanks for this -- it's a good point! Might even need to be there by default, including empty objects.
Lemme check in with some places where this came from and verify that it makes sense. In the meantime lemme know what you think about having this as a default :)
My use case does have a need to preserve empty arrays. My 2c is that the default would be to keep empty arrays and objects as that is the least "change-y". But regardless of the default it would be great to have the option to include these.