vscode-moon-zod-schema
Generate moon_zod schema from any JSON file with one click — copy ready-to-use @moon_zod code to your clipboard.
Features
- CodeLens button — opens automatically when editing
.json files
- Context menu — right-click any JSON file and select "moon_zod: Copy Schema from Current File"
- JSON Schema import — convert existing JSON Schema to moon_zod code via
--from-json-schema
- Powered by
Betterlol/moon_zod — delegates schema inference and code generation to the real moon_zod library, so the output stays in sync with library updates
Requirements
Installation
From VSIX
vsce package
code --install-extension vscode-moon-zod-schema-*.vsix
From Marketplace (once published)
Search "moon_zod Schema Generator" in the Extensions pane.
Usage
- Open any
.json file in VS Code
- Click "Copy moon_zod Schema" in the editor top bar, or right-click → "moon_zod: Copy Schema from Current File"
- The generated
@moon_zod code is copied to your clipboard
The schema is generated via the bundled MoonBit package at gen/, which delegates to Betterlol/moon_zod for inference and code generation.
How It Works
The extension bundles a small MoonBit CLI tool (gen/) that runs under the hood:
moon run gen -- --verbose '<json>'
The output is parsed for ── Generated moon_zod Schema ──, and everything after that marker is copied to the clipboard.
The gen/ package uses:
@moon_zod.json_infer_schema — infer a schema from a raw JSON value
@moon_zod.schema_to_moon_zod_code — render the schema as MoonBit source code
@moon_zod.json_schema_to_moon_zod — convert JSON Schema to moon_zod code
You can also use the CLI standalone:
moon run gen -- '{"name": "Alice"}'
moon run gen -- --from-json-schema '{"type": "object", "properties": {...}}'
moon run gen -- --verbose '{"name": "Alice"}'
Development
# Install dependencies
moon add Betterlol/moon_zod
# Build & test
moon run gen -- '{"hello": "world"}'
# Package
npm install -g @vscode/vsce
vsce package
License
Apache-2.0