patch to make this work for nested objects

Simple implementation. I extracted the trim logic into a `function trim(obj)` that gets called recursively `if (typeof v === 'object')`.