Add null check on sub keys for hash toJSON