def _flatten(prefix, obj):

    fields = []

    for key, value in obj.items():

        new_key = f"{prefix}.{key}" if prefix else key

        if isinstance(value, dict):

            fields.extend(_flatten(new_key, value))

        elif isinstance(value, list):

            val = "|".join(str(v) for v in value)
            fields.append(f"{new_key}={val}")

        else:

            fields.append(f"{new_key}={value}")

    return fields


def json_to_toon(data):

    if "items" not in data:
        raise ValueError("JSON must contain 'items'")

    lines = []

    for item in data["items"]:

        fields = _flatten("", item)

        lines.append("; ".join(fields))

    return "\n".join(lines)