def _merge_objects(obj1, obj2):
    """Recursive merge obj2 into obj1. Objects can be dicts and lists."""
    if type(obj1) == list:
        obj1.extend(obj2)
        return obj1
    for k2, v2 in obj2.iteritems():
        v1 = obj1.get(k2)
        if type(v2) == type(v1) in (dict, list):
            _merge_objects(v1, v2)
        else:
            obj1[k2] = v2
    return obj1