def encode_to_json(history_list):
    """
    Encodes this MarketHistoryList instance to a JSON string.

    :param MarketHistoryList history_list: The history instance to serialize.
    :rtype: str
    """
    rowsets = []
    for items_in_region_list in history_list._history.values():
        region_id = items_in_region_list.region_id
        type_id = items_in_region_list.type_id
        generated_at = gen_iso_datetime_str(items_in_region_list.generated_at)

        rows = []
        for entry in items_in_region_list.entries:
            historical_date = gen_iso_datetime_str(entry.historical_date)

            # The order in which these values are added is crucial. It must
            # match STANDARD_ENCODED_COLUMNS.
            rows.append([
                historical_date,
                entry.num_orders,
                entry.total_quantity,
                entry.low_price,
                entry.high_price,
                entry.average_price,
            ])

        rowsets.append(dict(
            generatedAt = generated_at,
            regionID = region_id,
            typeID = type_id,
            rows = rows,
        ))

    json_dict = {
        'resultType': 'history',
        'version': '0.1',
        'uploadKeys': history_list.upload_keys,
        'generator': history_list.history_generator,
        'currentTime': gen_iso_datetime_str(now_dtime_in_utc()),
        # This must match the order of the values in the row assembling portion
        # above this.
        'columns': STANDARD_ENCODED_COLUMNS,
        'rowsets': rowsets,
    }

    return json.dumps(json_dict)
Encodes this MarketHistoryList instance to a JSON string.

    :param MarketHistoryList history_list: The history instance to serialize.
    :rtype: str