function cleanOptions(optionsObj) {
    if (!optionsObj || typeof optionsObj !== 'object') return {};
    const cleaned = {};
    for (const [key, value] of Object.entries(optionsObj)) {
        // Aggressively remove any key that looks like JSON or contains JSON markers
        if (key.includes('{') || key.includes('}') || key.includes('[') || key.includes(']') || key.includes(':')) {
            console.log(`DEBUG: Removing parasitic key: ${key}`);
            continue;
        }
        cleaned[key] = value;
    }
    return cleaned;
}

const corrupted = {
    "finish": "Galvanized",
    '{"finish":"Galvanized"}': "Galvanized",
    '{"finish":"Galvanized","length":"76mm upto 210mm"}': "Galvanized"
};

const cleaned = cleanOptions(corrupted);
console.log('Result:', JSON.stringify(cleaned, null, 2));
