import csv
import json


def csv2json(csv_filepath, json_filepath=None):
    """
    convert a CSV to JSON.
    """
    items = []
    with open(csv_filepath, encoding="utf-8") as csvf:
        csvReader = csv.DictReader(csvf)
        for row in csvReader:
            items.append(row)

    if json_filepath is None:
        return json.dumps(items)

    with open(json_filepath, "w", encoding="utf-8") as f:
        json.dump(items, f, indent=4)
        return json.dumps(items)