Removing duplicates

How do I remove duplicate interface {} on the basis of any element? like userid


    "phonebook": [
        {
            "contact_id": 1,
            "user_id": 13,
            "userid": 2,
            "username": "Tester"
        },
        {
            "contact_id": 1,
            "user_id": 13,
            "userid": 2,
            "username": "Tester"
        },
        {
            "contact_id": 3,
            "user_id": 13,
            "userid": 22,
            "username": "Tester"
        }
    ]

I do not see even a single interface{}, can you please elaborate on what you are after?

Sorry. I want to remove duplicate from array of hashes on basis of attributes i.e “userid”. For example
Input


    "phonebook": [
        {
            "contact_id": 1,
            "user_id": 13,
            "userid": 2,
            "username": "Tester"
        },
        {
            "contact_id": 1,
            "user_id": 13,
            "userid": 2,
            "username": "Tester"
        },
        {
            "contact_id": 3,
            "user_id": 13,
            "userid": 22,
            "username": "Tester"
        }
    ]

***Required Output is: ***

"phonebook": [
    {
        "contact_id": 1,
        "user_id": 13,
        "userid": 2,
        "username": "Tester"
    },
    {
        "contact_id": 3,
        "user_id": 13,
        "userid": 22,
        "username": "Tester"
    }
]

You mean like this? https://play.golang.org/p/Ns_Cl9fPmW9

2 Likes

Thanks buddy for helping newbie on GOLang and I must appreciate the response time of the community.