{"id":49812,"library":"yaml-to-json-schema","title":"yaml-to-json-schema","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/rhrn/yaml-to-json-schema","tags":["javascript","yaml","json","schema","swagger","openapi","asyncapi","typescript"],"install":[{"cmd":"npm install yaml-to-json-schema","lang":"bash","label":"npm"},{"cmd":"yarn add yaml-to-json-schema","lang":"bash","label":"yarn"},{"cmd":"pnpm add yaml-to-json-schema","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export only. No default export.","wrong":"import yamlToJsonSchema from 'yaml-to-json-schema'","symbol":"convert","correct":"import { convert } from 'yaml-to-json-schema'"},{"note":"ESM-only package; CommonJS require will fail.","wrong":"const { convertSync } = require('yaml-to-json-schema')","symbol":"convertSync","correct":"import { convertSync } from 'yaml-to-json-schema'"},{"note":"Converts a YAML file directly. Also exists as convertFromFileSync.","wrong":"","symbol":"convertFromFile","correct":"import { convertFromFile } from 'yaml-to-json-schema'"}],"quickstart":{"code":"import { convertFromFile, convert } from 'yaml-to-json-schema';\n\n// Convert a file\nconst schema = convertFromFile('openapi.yaml');\nconsole.log(JSON.stringify(schema, null, 2));\n\n// Or convert a string\nconst yamlString = `\nopenapi: \"3.0.0\"\ninfo:\n  title: Sample API\n  version: \"1.0.0\"\npaths:\n  /items:\n    get:\n      responses:\n        '200':\n          description: OK\n`;\nconvert(yamlString).then(result => {\n  console.log(JSON.stringify(result, null, 2));\n});","lang":"typescript","description":"Demonstrates converting a YAML string and file to JSON Schema using named imports from the ESM module."},"warnings":[{"fix":"Use import syntax or dynamic import(). If using CommonJS, wrap in an async function: const { convert } = await import('yaml-to-json-schema');","message":"Package is ESM-only; CommonJS require() will throw a MODULE_NOT_FOUND or ERR_REQUIRE_ESM error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pre-process YAML to dereference anchors before conversion.","message":"The library does not explicitly deprecate any features, but note that some YAML constructs (e.g., anchors, aliases) may not be fully supported.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use tools like AJV to validate or adjust the schema as needed.","message":"Conversion result is a JSON Schema object; further validation or transformation may be needed for strict compliance with specific JSON Schema drafts.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.2':23 'ajv':65 'api':52 'asyncapi':18,72 'base':51 'cli':7 'convers':46 'convert':12 'differenti':44 'direct':45 'enabl':57 'file':15 'global':35 'infrequ':30 'javascript':66 'json':4,20,55,68 'key':43 'latest':26 'like':62 'local':39 'npm':42 'openapi':16,71 'popular':48 'process':59 'programmat':9 'project':38 'project-loc':37 'quicktyp':63 'releas':28 'schema':5,21,56,69 'specif':14,53 'stabl':27 'support':33 'swagger':17,70 'tool':10,61 'typescript':73 'updat':31 'usag':40 'version':22 'via':41 'yaml':2,13,50,67 'yaml-bas':49 'yaml-to-json-schema':1","created_at":"2026-06-07T17:03:43.526964+00:00","updated_at":"2026-06-07T17:03:43.526964+00:00","problems":[{"fix":"Change to import { convert } from 'yaml-to-json-schema'; or use dynamic import.","cause":"Using CommonJS require() on an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/node_modules/yaml-to-json-schema/dist/index.js"},{"fix":"Use named import: import { convert } from 'yaml-to-json-schema';","cause":"Attempting to use default import when package only exports named exports.","error":"TypeError: yamlToJsonSchema is not a function"},{"fix":"Run npm install --save-dev yaml-to-json-schema","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'yaml-to-json-schema'"},{"fix":"Ensure YAML string is valid. Use YAML lint tools to validate before conversion.","cause":"Passing invalid YAML string to convert() function.","error":"SyntaxError: Unexpected token ':' at ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/rhrn/yaml-to-json-schema","github":"https://github.com/rhrn/yaml-to-json-schema","docs":null,"changelog":null,"pypi":null,"npm":"yaml-to-json-schema","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}