VOOZH about

URL: https://www.geeksforgeeks.org/javascript/how-to-convert-returned-json-object-properties-to-camelcase-in-lodash/

⇱ How to Convert returned JSON Object Properties to camelCase in Lodash? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Convert returned JSON Object Properties to camelCase in Lodash?

Last Updated : 23 Jul, 2025

When working with JSON data in JavaScript, it's common to need consistent property naming conventions, such as camelCase. Lodash provides utilities that can help with this transformation.

These are the various approaches to convert object properties to camelCase using Lodash:

Using _.mapKeys() Method

We use _.mapKeys() to create an object composed of the keys generated by running each enumerable string key of the object through a given function. We can define a function to convert each key to camelCase.

Syntax:

_.mapKeys(object, iteratee);

Example: In this example, we will be using the Using _.mapKeys() and a Custom Function.

Output:

{
"firstName": "Prateek",
"lastName": "Sharma"
}

Using _.transform() Method

We use _.transform() to transform an object or array into a new structure, thus allowing us to apply custom logic during the transformation.

Syntax:

_.transform(object, iteratee, [accumulator]);

Example: In this example we will be using the Using _.transform() Method.

Output:

{
"firstName": "Prateek",
"lastName": "Sharma"
}

Using _.reduce() Method

We use _.reduce() method to iterate over an object and accumulate results based on our custom logic, which in this case involves converting keys to camelCase.

Syntax:

_.reduce(collection, iteratee, [accumulator]);

Example: In this example we will be using the Using _.reduce() Method.

Output:

{
"firstName": "Prateek",
"lastName": "Sharma"
}

Using _.merge() Method with a Recursive Function

We can use _.merge()  to recursively convert properties, especially useful when dealing with nested objects.

Syntax:

_.merge(object, [sources]);

Example: In this example we will be using the Using _.merge() with a Recursive Function.

Output:

{
"userInfo": {
"firstName": "Prateek",
"lastName": "Sharma"
}
}

Conclusion

In this article, we explored multiple approaches to converting JSON object properties to camelCase using Lodash. Each method has its strengths, and the choice of which to use can depend on the specific requirements of our project, such as whether we're handling nested objects or need a straightforward conversion. With Lodash, transforming object properties becomes efficient and easy.

Comment