How to remove the duplicate key from json array

Hi Team,

I have used invoke method to add get the JSON array. how to check if there are duplicate keys in this jsonarray. I am unable to check for the duplicates in it.

Please help me to resolve this issue

May we ask you to share some sample data with us. Thanks

2 Likes

I’m facing a similar issue too! A sample json array would be:
{
admin: false,
default:true,
admin:true
}
The above array has duplicate admin keys.I need to throw an error when the user enters duplicate keys.

Hi @Harshini_Lakshmi ,

Welcome to the Community.

@ppr , @Robinnavinraj_S , @90s_Developer, @THIRU_NANI can also help you here.

Thanks !

1 Like

Hi @Harshini_Lakshmi ,

My suggestion for your question is try converting your json array to datatable by using the deserialize Json Array so that once you get the json array in datatable format you will be able to find out whether the key is having duplicates or not. thanks.

2 Likes

Hi @Harshini_Lakshmi ,

From the solution @kirankumar.mahanthi1 provided you can convert your Json into a datatable

1.Deserialize the Array
2.Assign a datatable to JsonConvert.DeserializeObject(of DataTable)(YourJArray.ToString)
3. Then post that check for duplicacy.

Thanks

2 Likes

Oh okay, I’ll do that. Thank you @Shikhar_Tandon @kirankumar.mahanthi1

1 Like

@Harshini_Lakshmi
may we ask you to open a new topic on this., Your case is about duplicated Properties related to the property name. This Topic is about duplicated items within an JSON array

A handling via datatable conversion we would not recommend.

Serialized JSON had following result
grafik

So working on text level could be a better option

1 Like