Registry / devops / yaml-to-json-schema

yaml-to-json-schema

JSON →
library1.0.2jsnpmunverified

A CLI and programmatic tool that converts YAML specification files (OpenAPI, Swagger, AsyncAPI) into JSON Schema. Version 1.0.2 is the latest stable release, with infrequent updates. It supports both global and project-local usage via npm. Key differentiator: direct conversion from popular YAML-based API specifications to JSON Schema, enabling further processing with tools like quicktype or AJV.

npm install yaml-to-json-schema
INSTALL
IMPORT
SIG · YAML-TO-JSON-SCHEM
Y
yaml-to-json-schema
devopsjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

convert
import { convert } from 'yaml-to-json-schema'
import yamlToJsonSchema from 'yaml-to-json-schema'
Named export only. No default export.
convertSync
import { convertSync } from 'yaml-to-json-schema'
const { convertSync } = require('yaml-to-json-schema')
ESM-only package; CommonJS require will fail.
convertFromFile
import { convertFromFile } from 'yaml-to-json-schema'
Converts a YAML file directly. Also exists as convertFromFileSync.

Demonstrates converting a YAML string and file to JSON Schema using named imports from the ESM module.

import { convertFromFile, convert } from 'yaml-to-json-schema'; // Convert a file const schema = convertFromFile('openapi.yaml'); console.log(JSON.stringify(schema, null, 2)); // Or convert a string const yamlString = ` openapi: "3.0.0" info: title: Sample API version: "1.0.0" paths: /items: get: responses: '200': description: OK `; convert(yamlString).then(result => { console.log(JSON.stringify(result, null, 2)); });
Debug
Known issues
gotchaPackage is ESM-only; CommonJS require() will throw a MODULE_NOT_FOUND or ERR_REQUIRE_ESM error.
fix
Use import syntax or dynamic import(). If using CommonJS, wrap in an async function: const { convert } = await import('yaml-to-json-schema');
affects: >=1.0.0
deprecatedThe library does not explicitly deprecate any features, but note that some YAML constructs (e.g., anchors, aliases) may not be fully supported.
fix
Pre-process YAML to dereference anchors before conversion.
affects: >=1.0.0
gotchaConversion result is a JSON Schema object; further validation or transformation may be needed for strict compliance with specific JSON Schema drafts.
fix
Use tools like AJV to validate or adjust the schema as needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/node_modules/yaml-to-json-schema/dist/index.js
Using CommonJS require() on an ESM-only package.
fix
Change to import { convert } from 'yaml-to-json-schema'; or use dynamic import.
TypeError: yamlToJsonSchema is not a function
Attempting to use default import when package only exports named exports.
fix
Use named import: import { convert } from 'yaml-to-json-schema';
Cannot find module 'yaml-to-json-schema'
Package not installed or not in node_modules.
fix
Run npm install --save-dev yaml-to-json-schema
SyntaxError: Unexpected token ':' at ...
Passing invalid YAML string to convert() function.
fix
Ensure YAML string is valid. Use YAML lint tools to validate before conversion.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
25
OpenAI (training)
1
Resources
yaml-to-json-schema — npm install yaml-to-json-schema · libregistry