Convert a record/struct field to its JSON representation.

    Args:
        fields ( \
            Sequence[:class:`~google.cloud.bigquery.schema.SchemaField`], \
        ):
            The :class:`~google.cloud.bigquery.schema.SchemaField`s of the
            record's subfields to use for type conversion and field names.
        row_value (Union[Tuple[Any], Mapping[str, Any]):
            A tuple or dictionary to convert to JSON-serializable values.

    Returns:
        Mapping[str, any]:
            A JSON-serializable dictionary.

def _record_field_to_json(fields, row_value):
    """Convert a record/struct field to its JSON representation.

    Args:
        fields ( \
            Sequence[:class:`~google.cloud.bigquery.schema.SchemaField`], \
        ):
            The :class:`~google.cloud.bigquery.schema.SchemaField`s of the
            record's subfields to use for type conversion and field names.
        row_value (Union[Tuple[Any], Mapping[str, Any]):
            A tuple or dictionary to convert to JSON-serializable values.

    Returns:
        Mapping[str, any]:
            A JSON-serializable dictionary.
    """
    record = {}
    isdict = isinstance(row_value, dict)

    for subindex, subfield in enumerate(fields):
        subname = subfield.name
        if isdict:
            subvalue = row_value.get(subname)
        else:
            subvalue = row_value[subindex]
        record[subname] = _field_to_json(subfield, subvalue)
    return record