This package, `json2yaml`, provides a command-line utility and a programmatic API for converting JSON data into human-readable YAML format. First released with a Node.js `0.2.0` engine requirement, its current stable version is 1.1.0. The tool primarily aims to pretty-print JSON, transforming it into the more visually appealing, whitespace-based YAML notation, leveraging the fact that JSON is technically a proper subset of YAML. This means any valid JSON is also valid YAML, but `json2yaml` focuses on converting to the more common, indented YAML style for improved human readability. The project appears to have ceased active development around 9 years ago, suggesting it is no longer actively maintained and may have compatibility issues with modern JavaScript environments.
npm install json2yamlVerified import paths — ran on the pinned version, not inferred.
This code snippet demonstrates how to use `json2yaml` programmatically to convert a JavaScript object (which translates to JSON) into a human-readable YAML string using the `stringify` method.
Consider using actively maintained alternatives like `js-yaml` or `yaml` for modern Node.js environments. If you must use `json2yaml`, run it in a legacy Node.js environment or a container configured with older Node.js versions.
Ensure your project is configured for CommonJS (e.g., `"type": "commonjs"` in `package.json`) or use dynamic `import()` if you are in an ESM context and need to load a CJS module.
Prioritize using actively maintained libraries for security-sensitive applications. If this package is critical, consider auditing its source code or forking it for maintenance.
Create a declaration file (e.g., `json2yaml.d.ts`) with `declare module 'json2yaml' { ... }` or use `@ts-ignore` on the import statement.Ensure your Node.js project is running in a CommonJS context (e.g., `"type": "commonjs"` in `package.json` or explicitly using `.cjs` file extensions). For browsers, use a bundler like Webpack or Rollup that handles CommonJS modules.
Ensure you are using `const json2yaml = require('json2yaml');` and then calling `json2yaml.stringify(data);`. The `stringify` method is a property of the module's default export.Install the package globally using `npm install -g json2yaml`. If the problem persists, ensure your npm global bin directory is included in your system's PATH environment variable (e.g., `~/.npm-global/bin`).
No dependency data recorded yet.