<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _tsv2json(in_tsv, out_json, index_column, additional_metadata=None, drop_columns=None, enforce_case=True):
 """ Convert metadata from TSV format to JSON format. Parameters in_tsv: str Path to the metadata in TSV format. out_json: str Path where the metadata should be saved in JSON format after conversion. If this is None, then a dictionary is returned instead. index_column: str Name of the column in the TSV to be used as an index (top-level key in the JSON). additional_metadata: dict Any additional metadata that should be applied to all entries in the JSON. drop_columns: list List of columns from the input TSV to be dropped from the JSON. enforce_case: bool Indicates whether BIDS case conventions should be followed. Currently, this means that index fields (column names in the associated data TSV) use snake case and other fields use camel case. Returns ------- str Path to the metadata saved in JSON format. """

    import pandas as pd
    # Adapted from https://dev.to/rrampage/snake-case-to-camel-case-and- ...
    # back-using-regular-expressions-and-python-m9j
    re_to_camel = r'(.*?)_([a-zA-Z0-9])'
    re_to_snake = r'(^.+?|.*?)((?<![_A-Z])[A-Z]|(?<![_0-9])[0-9]+)'

    def snake(match):
        return '{}_{}'.format(match.group(1).lower(), match.group(2).lower())

    def camel(match):
        return '{}{}'.format(match.group(1), match.group(2).upper())

    # from fmriprep
    def less_breakable(a_string):
        """ hardens the string to different envs (i.e. case insensitive, no
        whitespace, '#' """
        return ''.join(a_string.split()).strip('#')

    drop_columns = drop_columns or []
    additional_metadata = additional_metadata or {}
    tsv_data = pd.read_csv(in_tsv, '\t')
    for k, v in additional_metadata.items():
        tsv_data[k] = v
    for col in drop_columns:
        tsv_data.drop(labels=col, axis='columns', inplace=True)
    tsv_data.set_index(index_column, drop=True, inplace=True)
    if enforce_case:
        tsv_data.index = [re.sub(re_to_snake, snake,
                                 less_breakable(i), 0).lower()
                          for i in tsv_data.index]
        tsv_data.columns = [re.sub(re_to_camel, camel,
                                   less_breakable(i).title(), 0)
                            for i in tsv_data.columns]
    json_data = tsv_data.to_json(orient='index')
    json_data = json.JSONDecoder(
        object_pairs_hook=OrderedDict).decode(json_data)
    if out_json is None:
        return json_data

    with open(out_json, 'w') as f:
        json.dump(json_data, f, indent=4)
    return out_json