{"id":11176,"library":"json-to-pretty-yaml","title":"JSON to Pretty YAML Converter","description":"This Node.js module provides a straightforward utility for converting JSON data into human-readable, 'pretty' YAML format. The package is currently at version 1.2.2, which was last updated over six years ago as of early 2026. It functions as a lightweight wrapper around the `js-yaml` library, specifically utilizing its stringification capabilities to produce well-formatted YAML output. Due to its age and lack of recent updates, users should be aware of potential compatibility issues with newer Node.js versions (e.g., ESM compatibility) or security concerns related to its underlying dependencies, which may not have received recent patches. The module's primary differentiator is its simplicity and direct focus on producing aesthetically pleasing YAML from JSON inputs without complex configuration options.","status":"abandoned","version":"1.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/alexcrist/json-to-pretty-yaml","tags":["javascript","yml","yaml","json","cli","util"],"install":[{"cmd":"npm install json-to-pretty-yaml","lang":"bash","label":"npm"},{"cmd":"yarn add json-to-pretty-yaml","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-to-pretty-yaml","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for YAML serialization, used internally by `json-to-pretty-yaml` for its stringify method.","package":"js-yaml"}],"imports":[{"note":"This package is CommonJS-only. The imported 'YAML' object contains the `stringify` method.","wrong":"import YAML from 'json-to-pretty-yaml';","symbol":"YAML","correct":"const YAML = require('json-to-pretty-yaml');"},{"note":"You can destructure the `stringify` method directly if preferred, but it's still a CommonJS `require`.","wrong":"import { stringify } from 'json-to-pretty-yaml';","symbol":"stringify","correct":"const { stringify } = require('json-to-pretty-yaml');"}],"quickstart":{"code":"const fs = require('fs');\nconst path = require('path');\nconst YAML = require('json-to-pretty-yaml');\n\n// Create a dummy input.json file for demonstration\nconst inputJsonPath = path.join(__dirname, 'input.json');\nconst outputYamlPath = path.join(__dirname, 'output.yaml');\n\nconst inputJsonContent = {\n  \"project\": \"MyAwesomeProject\",\n  \"version\": \"1.0.0\",\n  \"config\": {\n    \"env\": \"development\",\n    \"features\": [\n      \"featureA\",\n      \"featureB\"\n    ]\n  },\n  \"settings\": null,\n  \"enabled\": true\n};\n\nfs.writeFileSync(inputJsonPath, JSON.stringify(inputJsonContent, null, 2));\n\n// Load the JSON data (or use an object directly)\nconst json = require(inputJsonPath);\n\n// Convert JSON to YAML\nconst yamlData = YAML.stringify(json);\n\n// Write the YAML to a file\nfs.writeFileSync(outputYamlPath, yamlData);\n\nconsole.log(`Converted JSON to YAML:\n${yamlData}`);\nconsole.log(`Output written to ${outputYamlPath}`);\n\n// Clean up dummy file\nfs.unlinkSync(inputJsonPath);\nfs.unlinkSync(outputYamlPath);","lang":"javascript","description":"Demonstrates how to convert a JSON object to a pretty YAML string and save it to a file."},"warnings":[{"fix":"Always use `const YAML = require('json-to-pretty-yaml');` in your Node.js code.","message":"This package is CommonJS-only (`require`) and does not natively support ES Modules (`import`). Attempting to `import` it will result in errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new projects or if security/maintenance is a concern, consider using a actively maintained alternative like `js-yaml` directly, which `json-to-pretty-yaml` wraps.","message":"The package has not been updated in over six years and is considered abandoned. This means no new features, bug fixes, or security patches will be released.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Audit your dependency tree. If possible, consider replacing `json-to-pretty-yaml` with a direct dependency on a current version of `js-yaml` to ensure up-to-date security and features.","message":"The package depends on `js-yaml@^3.9.0`, which is an old version of the `js-yaml` library. This may expose projects to known vulnerabilities or compatibility issues present in older `js-yaml` releases.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test thoroughly in your target Node.js environment. If issues arise, migration to a more modern YAML serialization library is recommended.","message":"Due to its age, this package might exhibit compatibility issues with very recent Node.js runtime versions or modern JavaScript language features (e.g., async/await within its own codebase, though its API is synchronous).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"If in an ES module environment, you must dynamically import: `const YAML = await import('json-to-pretty-yaml');` and then `YAML.default.stringify(...)`. In a CommonJS environment, use `const YAML = require('json-to-pretty-yaml');`.","cause":"Attempting to use ES module `import { stringify } from 'json-to-pretty-yaml';` in an ES module context.","error":"TypeError: (0 , json_to_pretty_yaml_1.stringify) is not a function"},{"fix":"Ensure the package is installed: `npm install json-to-pretty-yaml`. Verify the module name is correctly spelled in your `require()` statement.","cause":"The package is not installed or the import path is incorrect.","error":"Cannot find module 'json-to-pretty-yaml'"}],"ecosystem":"npm"}