def prompt_overwrite_json(original, new, target_path, dumps=json_dumps):
    """
    Prompt end user with a diff of original and new json that may
    overwrite the file at the target_path.  This function only displays
    a confirmation prompt and it is up to the caller to implement the
    actual functionality.  Optionally, a custom json.dumps method can
    also be passed in for output generation.
    """

    # generate compacted ndiff output.
    diff = '\n'.join(l for l in (
        line.rstrip() for line in difflib.ndiff(
            json_dumps(original).splitlines(),
            json_dumps(new).splitlines(),
        ))
        if l[:1] in '?+-' or l[-1:] in '{}' or l[-2:] == '},')
    basename_target = basename(target_path)
    return prompt(
        "Generated '%(basename_target)s' differs with '%(target_path)s'.\n\n"
        "The following is a compacted list of changes required:\n"
        "%(diff)s\n\n"
        "Overwrite '%(target_path)s'?" % locals(),
        choices=(
            ('Yes', True),
            ('No', False),
        ),
        default_key=1,
    )
def prompt_overwrite_json ( original , new , target_path , dumps = json_dumps ) : diff = '\n' . join ( l for l in ( line . rstrip ( ) for line in difflib . ndiff ( json_dumps ( original ) . splitlines ( ) , json_dumps ( new ) . splitlines ( ) , ) ) if l [ : 1 ] in '?+-' or l [ - 1 : ] in '{}' or l [ - 2 : ] == '},' ) basename_target = basename ( target_path ) return prompt ( "Generated '%(basename_target)s' differs with '%(target_path)s'.\n\n" "The following is a compacted list of changes required:\n" "%(diff)s\n\n" "Overwrite '%(target_path)s'?" % locals ( ) , choices = ( ( 'Yes' , True ) , ( 'No' , False ) , ) , default_key = 1 , )
Prompt end user with a diff of original and new json that may
    overwrite the file at the target_path.  This function only displays
    a confirmation prompt and it is up to the caller to implement the
    actual functionality.  Optionally, a custom json.dumps method can
    also be passed in for output generation.