<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def merge(move, output_dir, sources):
 """ Merge multiple results folder into one, by copying the results over to a new folder. For a faster operation (which on the other hand destroys the campaign data if interrupted), the move option can be used to directly move results to the new folder. """

    # Get paths for all campaign JSONS
    jsons = []
    for s in sources:
        filename = "%s.json" % os.path.split(s)[1]
        jsons += [os.path.join(s, filename)]

    # Check that the configuration for all campaigns is the same
    reference_config = TinyDB(jsons[0]).table('config')
    for j in jsons[1:]:
        for i, j in zip(reference_config.all(), TinyDB(j).table('config').all()):
            assert i == j

    # Create folders for new results directory
    filename = "%s.json" % os.path.split(output_dir)[1]
    output_json = os.path.join(output_dir, filename)
    output_data = os.path.join(output_dir, 'data')
    os.makedirs(output_data)

    # Create new database
    db = TinyDB(output_json)
    db.table('config').insert_multiple(reference_config.all())

    # Import results from all databases to the new JSON file
    for s in sources:
        filename = "%s.json" % os.path.split(s)[1]
        current_db = TinyDB(os.path.join(s, filename))
        db.table('results').insert_multiple(current_db.table('results').all())

    # Copy or move results to new data folder
    for s in sources:
        for r in glob.glob(os.path.join(s, 'data/*')):
            basename = os.path.basename(r)
            if move:
                shutil.move(r, os.path.join(output_data, basename))
            else:
                shutil.copytree(r, os.path.join(output_data, basename))

    if move:
        for s in sources:
            shutil.rmtree(os.path.join(s, 'data/*'))
            shutil.rmtree(os.path.join(s, "%s.json" % os.path.split(s)[1]))
            shutil.rmtree(s)