import json

from ActionStreamer.WebService.API import PatchOperation


def add_patch_operation(operations, field_name, value):
    operations.append(PatchOperation(field_name, value))


def generate_patch_json(operations):
    # Convert all values to strings
    operations_str = [{k: str(v) for k, v in vars(op).items()} for op in operations]
    json_data = json.dumps(operations_str)
    return json_data