
Security News
/Company News
Socket Is Sponsoring Composer and Packagist
Socket has joined the new Composer and Packagist sponsorship program as a launch sponsor, supporting the team that keeps PHP's package ecosystem secure.
zod-to-camel-case
Advanced tools
Convert zod schema object keys to camel case.
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"],
},
});
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
MIT
FAQs
Convert zod schema object keys to camel case
The npm package zod-to-camel-case receives a total of 369 weekly downloads. As such, zod-to-camel-case popularity was classified as not popular.
We found that zod-to-camel-case demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
/Company News
Socket has joined the new Composer and Packagist sponsorship program as a launch sponsor, supporting the team that keeps PHP's package ecosystem secure.

Research
/Security News
Benign-looking npm packages split malicious functionality across a dependency chain that deploys a cross-platform RAT targeting Alibaba developers.

Research
/Security News
Two Joyfill npm beta releases contain an import-time implant that uses blockchain transactions to retrieve a remote-access trojan.