import json


def list_to_json_array(value_list, array_name, value_name=None, start=True, stop=True):
    """
    Creates a json array from a list. If the optional value_name is passed then the list becomes a json array of dictionary objects.
    """
    if start:
        start_brace = "{"
    else:
        start_brace = " "

    if stop:
        stop_brace = "}"
    else:
        stop_brace = ","
    if value_name is None:
        return "%s\"%s\": %s%s" % (start_brace, array_name, json.dumps(value_list), stop_brace)

    lst = []

    for value in value_list:
        data_dict = {value_name: value}
        lst.append(data_dict)

    return "%s\"%s\": %s%s" % (start_brace, array_name, json.dumps(lst), stop_brace)