JSON Convert all keys to lowercase

JSON Convert all keys to lowercase

There is no inbuilt method in javascript to convert all keys to lowercase. In this case, you have to use some logic to convert all keys to lowercase.

The following example will demonstrate how to convert all keys to lowercase.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON Convert all keys to lowercase</h1> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 36 }, { "NAME": "Jade", "AGE": 24 } ]; function myFunction(){ for(var i = 0; i < data.length; i++){ for (var key in data[i]) { if(key.toLowerCase() !== key){ data[i][key.toLowerCase()] = data[i][key]; delete data[i][key]; } } } console.log(data); } </script> </body> </html>

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author