def transform_data(input_json):
    # Initialize an empty list to store the transformed data
    transformed_data = []
    # print(input_json['data'])
    # Iterate through each item in the 'data' list of the input JSON
    for item in input_json['data']:
        # Extract required information from the current item
        firstName = item.get('firstName', '')
        lastName = item.get('lastName', '')
        contactInfo = item.get('contactInfo', '')

        # Initialize variables for nested data
        email = ''
        company = ''
        domain = ''
        linkedin_id = ''

        # Check and extract company and email information if available
        if item.get('companies') and len(item['companies']) > 0:
            company_info = item['companies'][0]
            email_info = company_info.get('email', {})
            email = email_info.get('value', '')
            company_data = company_info.get('company', {})
            company = company_data.get('name', '')
            domain = company_data.get('domain', '')

        # Check and extract LinkedIn ID if available
        if item.get('linkedin') and len(item['linkedin']) > 0:
            linkedin_info = item['linkedin'][0]
            linkedin_id = linkedin_info.get('id', '')
        
        # Construct a new dictionary with the required format
        transformed_entry = {
            "firstName": firstName,
            "lastName": lastName,
            "contactInfo": contactInfo,
            "email": email,
            "company": company,
            "domain": domain,
            "linkedin_id": linkedin_id,
        }
        
        # Append the transformed entry to the list
        transformed_data.append(transformed_entry)
    
    # Return the list of transformed data
    return transformed_data

# Assuming 'input_json' is your JSON data
# Call the function with your JSON data as the argument
