Fix #1418 (problem with JSON unflatten when using common prefixes)

This is a fix for issue #1418 that doesn't break the tests. I've also added a new unit test for my case (i.e. property names with common prefixes, such as "photo" and "photographer").