def json_update(root, new_root):
    """Recursively update a JSON document with another JSON document, merging where necessary."""

    if isinstance(root, dict) and isinstance(new_root, dict):

        for field in new_root:

            field_value = root[field] if field in root else None
            new_field_value = new_root[field]

            root[field] = json_update(field_value, new_field_value)

        return root

    return new_root