import json


def category_lists(DataFrame, categorical_variables, threshold=50, return_type='json'):
    """
    Parameters
    ----------
    DataFrame : pandas.DataFrame
        DataFrame
    categorical_variables : list(str)
        Variable to examine the freqeuncy.    
    threshold : int, default 50
        Maximum number of categories expected
    return_type : {'json', 'dict'}, default 'json'
    
    Returns
    -------
    out : JSON str or dict
    """
    out = dict()
    for variable in categorical_variables:
        categories = DataFrame[variable].unique()
        if len(categories)>threshold:
            out[variable] = []
            print('Numebr of ategories > {}'.format(threshold))
        else:
            out[variable] = list(categories)
    
    if return_type=='json':
        out = json.dumps(out, indent = 4)
        
    return out