0

How to handle json duplicate keys from user input

How to handle json duplicate keys from user input I have an api where the user can give json array input, if the user entered a duplicate key i want to throw an error in TS,how to achieve it A sample json array would be: { Name: false, default:true, Name:true } The above array has duplicate Name keys.I need to throw an error when the user enters duplicate keys

9th Oct 2022, 7:47 AM
Jeya Prakash J
Jeya Prakash J - avatar
1 Réponse
+ 3
You can check does json object has key, check this article: https://www.freecodecamp.org/news/how-to-check-if-an-object-has-a-key-in-javascript/amp/ This can be used to prevent user from adding duplicate key
9th Oct 2022, 8:40 AM
PanicS
PanicS - avatar