🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

zod-to-camel-case

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-to-camel-case

Convert zod schema object keys to camel case

latest
Source
npmnpm
Version
0.9.0
Version published
Weekly downloads
502
29.72%
Maintainers
1
Weekly downloads
 
Created
Source

zod-to-camel-case

Convert zod schema object keys to camel case.

Usage

The zodToCamelCase supports both unidirectional and bidirectional transformation of zod schemas

zodToCamelCase (unidirectional)

By default zodToCamelCase supports unidirectional transformation of the schema.

So the input will be expected to in the original snake-case format. The output data/type will still be camel-case.

import { z } from "zod";
import zodToCamelCase from "zod-to-camel-case";

const userSchemaSnake = z.object({
  full_name: z.string(),
  user: z.object({
    email_addresses: z.array(z.email()),
  }),
});
const userSchema = zodToCamelCase(userSchemaSnake);

// Infer the type using zod
type User = z.infer<typeof userSchema>;
// type => { fullName: string, user: { emailAddresses: string[] } }

// This input is snake-case
const results = userSchema.parse({
  full_name: "Turanga Leela",
  user: {
    email_addresses: ["name@example.com"],
  },
});

// Assert that the output is camel-case
expect(results).toEqual({
  fullName: "Turanga Leela",
  user: {
    emailAddresses: ["name@example.com"],
  },
});

zodToCamelCase (bidirectional)

By passing {bidirectional: true} as a second option to zodToCamelCase will change the expected input to be camel-case.

import { z } from "zod";
import zodToCamelCase from "zod-to-camel-case";

const userSchemaSnake = z.object({
  full_name: z.string(),
  user: z.object({
    email_addresses: z.array(z.email()),
  }),
});
const userSchema = zodToCamelCase(userSchemaSnake, {
  bidirectional: true, // ‼️ enabling bidirectional mode
});

// Infer the type using zod
type User = z.infer<typeof userSchema>;
// type => { fullName: string, user: { emailAddresses: string[] } }

// This input is camel-case
// 🎉 The input to parse() & safeParse() is now camel case
const results = userSchema.parse({
  fullName: "Turanga Leela",
  user: {
    emailAddresses: ["name@example.com"],
  },
});

// Assert that the output is camel-case
expect(results).toEqual({
  fullName: "Turanga Leela",
  user: {
    emailAddresses: ["name@example.com"],
  },
});

Test

To run the tests run, in non-watch mode the coverage reports are available at ./coverage/index.html

npm test

Or for watch mode (no coverage reports)

npm run test:watch

codecov

License

MIT

FAQs

Package last updated on 24 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts