The enthusiasm to start experimenting and blogging again started a few weeks ago when I was studying for my AWS Solution Architect exam. Luckily I passed, man I was nervous, and decided fairly soon after passing the test that I wanted to get the Developer and DevOps certificates as well.
With studying for these certificates comes experimenting as well and today I bumped into a rather peculiar issue with loading a json document into a dynamo. The error: An AttributeValue may not contain an empty string. As it turns out, by design empty strings are not allowed as values.
Apparently a fix for this is an outstanding request since 2012, which makes me wonder whether it’s incredibly hard to fix or if there is an huge list of other feature requests with more added value that keeps the dynamodb team busy.
I decided to search the internet for a solution and I bumped into a recursive function on stackoverflow, unfortunately that specific function doesn’t have the desired result for all use cases, so I decided to write something myself.
The requirements are simple, all empty string key value pairs should be removed from the object and the object can be a collection of objects or a single object with practically unlimited nesting (as far as the function is concerned ). An object could look like this:
Inspired by the recursive function, but with very rusty recursive skills, I came up with the following which seems to work for all use cases so far.
When using the method like this is should remove both the q and t key value pairs
Hope it’s useful. If you have any comments please let me know. You can mail me for now, but I intend to enable disqus or something similar somewhere in the next few weeks.