For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/object/toCamelCaseKeys.md.

toCamelCaseKeys es-toolkit

Returns a new object with all keys in objects and arrays converted to camelCase.

Camel case is a naming convention where the first word is lowercase and the first letter of subsequent words is capitalized and concatenated. For example, it's written as camelCase.

const camelCased = toCamelCaseKeys(obj);

Usage

toCamelCaseKeys(obj)

Use toCamelCaseKeys when you want to convert all keys of an object to camel case. Nested objects and objects within arrays are also converted recursively.

For example, object keys are converted as follows:

  • snake_casecamelCase (e.g. user_iduserId)
  • PascalCasecamelCase (e.g. UserIduserId)
  • UPPERCASE_KEYScamelCase (e.g. FIRST_NAMEfirstName, LASTlast)
import { toCamelCaseKeys } from 'es-toolkit/object';

// Basic object conversion
const obj = { user_id: 1, first_name: 'John', last_name: 'Doe' };
const result = toCamelCaseKeys(obj);
// result is { userId: 1, firstName: 'John', lastName: 'Doe' }

// Objects within arrays are also converted
const users = [
  { user_id: 1, first_name: 'John' },
  { user_id: 2, first_name: 'Jane' },
];
const convertedUsers = toCamelCaseKeys(users);
// convertedUsers is [{ userId: 1, firstName: 'John' }, { userId: 2, firstName: 'Jane' }]

// Nested objects are fully converted
const nested = {
  user_data: {
    user_id: 1,
    contact_info: {
      email_address: '[email protected]',
      phone_number: '123-456-7890',
    },
  },
};
const nestedResult = toCamelCaseKeys(nested);
// nestedResult is {
//   userData: {
//     userId: 1,
//     contactInfo: {
//       emailAddress: '[email protected]',
//       phoneNumber: '123-456-7890'
//     }
//   }
// }

// PascalCase and uppercase keys are also converted
const raw = { UserId: 1, FIRST_NAME: 'JinHo', LAST: 'Yeom' };
const converted = toCamelCaseKeys(raw);
// converted is { userId: 1, firstName: 'JinHo', last: 'Yeom' }

Parameters

objTrequired

The object, array, or primitive value to convert keys to camelCase.

Returns

Returns a new object with all keys converted to camelCase.

ToCamelCaseKeys<T>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.