from random import shuffle


def gen_participant_json(passwords, expression, randomize=True):
    """
    Function to create new users and store them in a json file
    
    :param passwords: list with passwords
    :param expression: string that contain the fixed part of the username
    :param randomize: indicates whether the passwords should be assigned randomly
    :return: 
    """
    # First create a dict
    users = {}
    if randomize:
        shuffle(passwords)
    for i, pss in enumerate(passwords, 1):
        users["{}".format(i)] = {"username": "{0}{1}".format(expression, i), "password": pss}
    return users