https://github.com/nrjdalal/zod-meta-parser
A utility to extract metadata descriptions from Zod schemas into a structured format.
https://github.com/nrjdalal/zod-meta-parser
api conversions json meta parser schema zod
Last synced: 4 months ago
JSON representation
A utility to extract metadata descriptions from Zod schemas into a structured format.
- Host: GitHub
- URL: https://github.com/nrjdalal/zod-meta-parser
- Owner: nrjdalal
- License: mit
- Created: 2025-01-07T15:08:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-07T16:09:49.000Z (over 1 year ago)
- Last Synced: 2025-10-29T05:44:59.884Z (8 months ago)
- Topics: api, conversions, json, meta, parser, schema, zod
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/zod-meta-parser
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Zod Meta Parser
[](https://npmjs.org/package/zod-meta-parser)
[](https://npmjs.org/package/zod-meta-parser)
## Summary
`zod-meta-parser` is a utility that extracts metadata descriptions from [Zod schemas](https://github.com/colinhacks/zod) into a structured format. This is particularly useful for generating documentation or for other meta-programming purposes.
## Usage
### Basic Example
```typescript
import { z } from "zod"
import { zodMetaParser } from "zod-meta-parser"
const schema = z.object({
id: z.number(), // no description
email: z.string().describe(JSON.stringify({ unique: true })),
image: z
.string()
.optional()
.describe(JSON.stringify({ s3: true })),
createdAt: z.date().describe("Read-only field"),
}),
console.log(zodMetaParser(schema))
```
#### Expected Output
```json
{
"email": {
"_meta": {
"unique": true
}
},
"image": {
"_meta": {
"s3": true
}
},
"createdAt": {
"_meta": "Read-only field"
}
}
```
## Installation
You can install the package via npm:
```sh
npm install zod-meta-parser
```
or via bun (recommended):
```sh
bun add zod-meta-parser
```
## Features
- Extracts metadata descriptions from Zod schemas.
- Supports nested objects and various Zod types.
- Provides a structured output format for easy consumption.
## Options
The `zodMetaParser` function currently does not accept any additional options. All metadata extraction is done based on the structure and descriptions provided in the Zod schema.
## Known Issues
- The `zodToJsonSchema` library used internally might not handle all Zod types perfectly, such as `symbol`. Custom handling is added for types not supported natively.
- Ensure all fields you want metadata for are described using the `.describe()` method in Zod.
## Versioning
This package follows semantic versioning. New features and bug fixes will be released as minor or patch updates, while breaking changes will be released as major updates.
## Contributing
Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/nrjdalal/zod-meta-parser).
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/nrjdalal/zod-meta-parser/blob/master/LICENSE) file for details.
## Sponsors
If you enjoy this package, consider sponsoring the project on my [GitHub Sponsors page](https://github.com/sponsors/nrjdalal). Your support is greatly appreciated!
---
Feel free to adjust the links and other details as per your project specifics.