Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ES6 module to recursively convert snake case keys in an object to camel case using lodash.
export function camelCaseKeys(object) {
let camelCaseObject = _.cloneDeep(object)
if (_.isArray(camelCaseObject)) {
return, camelCaseKeys)
if (_.isString(camelCaseObject)) {
return camelCaseObject
camelCaseObject = _.mapKeys(camelCaseObject, (value, key) => _.camelCase(key))
// Recursively apply throughout object
return _.mapValues(camelCaseObject, (value) => {
if (_.isPlainObject(value)) {
return camelCaseKeys(value)
} else if (_.isArray(value)) {
return, camelCaseKeys)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment