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/toPascalCaseKeys.md.

toPascalCaseKeys es-toolkit

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

Pascal case is a naming convention where each word in an identifier is capitalized and concatenated. For example, it's written as PascalCase.

const pascalCased = toPascalCaseKeys(obj);

Usage

toPascalCaseKeys(obj)

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

For example, object keys are converted as follows:

  • snake_casePascalCase (e.g. user_idUserId)
  • camelCasePascalCase (e.g. UserIdUserId)
  • UPPERCASE_KEYSPascalCase (e.g. FIRST_NAMEFirstName, LASTLast)
import { toPascalCaseKeys } from 'es-toolkit/object';

// Basic object conversion
const obj = { user_id: 1, first_name: 'John', last_name: 'Doe' };
const result = toPascalCaseKeys(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 = toPascalCaseKeys(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 = toPascalCaseKeys(nested);
// nestedResult is {
//   UserData: {
//     UserId: 1,
//     ContactInfo: {
//       EmailAddress: '[email protected]',
//       PhoneNumber: '123-456-7890'
//     }
//   }
// }

// camelCase and uppercase keys are also converted
const raw = { userId: 1, FIRST_NAME: 'JinHo', LAST: 'Yeom' };
const converted = toPascalCaseKeys(raw);
// converted is { UserId: 1, FirstName: 'JinHo', Last: 'Yeom' }

Parameters

objTrequired

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

Returns

Returns a new object with all keys converted to PascalCase.

ToPascalCaseKeys<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.