Registry / serialization / json-to-pretty-yaml

json-to-pretty-yaml

JSON →
library1.2.2jsnpmunverified

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.

npm install json-to-pretty-yaml
INSTALL
IMPORT
SIG · JSON-TO-PRETTY-YAM
J
json-to-pretty-yaml
serializationjavascriptv1.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

YAML
const YAML = require('json-to-pretty-yaml');
import YAML from 'json-to-pretty-yaml';
This package is CommonJS-only. The imported 'YAML' object contains the `stringify` method.
stringify
const { stringify } = require('json-to-pretty-yaml');
import { stringify } from 'json-to-pretty-yaml';
You can destructure the `stringify` method directly if preferred, but it's still a CommonJS `require`.

Demonstrates how to convert a JSON object to a pretty YAML string and save it to a file.

const fs = require('fs'); const path = require('path'); const YAML = require('json-to-pretty-yaml'); // Create a dummy input.json file for demonstration const inputJsonPath = path.join(__dirname, 'input.json'); const outputYamlPath = path.join(__dirname, 'output.yaml'); const inputJsonContent = { "project": "MyAwesomeProject", "version": "1.0.0", "config": { "env": "development", "features": [ "featureA", "featureB" ] }, "settings": null, "enabled": true }; fs.writeFileSync(inputJsonPath, JSON.stringify(inputJsonContent, null, 2)); // Load the JSON data (or use an object directly) const json = require(inputJsonPath); // Convert JSON to YAML const yamlData = YAML.stringify(json); // Write the YAML to a file fs.writeFileSync(outputYamlPath, yamlData); console.log(`Converted JSON to YAML: ${yamlData}`); console.log(`Output written to ${outputYamlPath}`); // Clean up dummy file fs.unlinkSync(inputJsonPath); fs.unlinkSync(outputYamlPath);
Debug
Known issues
gotchaThis package is CommonJS-only (`require`) and does not natively support ES Modules (`import`). Attempting to `import` it will result in errors.
fix
Always use `const YAML = require('json-to-pretty-yaml');` in your Node.js code.
affects: >=1.0.0
breakingThe 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.
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.
affects: >=1.0.0
gotchaThe 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.
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.
affects: >=1.0.0
gotchaDue 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).
fix
Test thoroughly in your target Node.js environment. If issues arise, migration to a more modern YAML serialization library is recommended.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , json_to_pretty_yaml_1.stringify) is not a function
Attempting to use ES module `import { stringify } from 'json-to-pretty-yaml';` in an ES module context.
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');`.
Cannot find module 'json-to-pretty-yaml'
The package is not installed or the import path is incorrect.
fix
Ensure the package is installed: `npm install json-to-pretty-yaml`. Verify the module name is correctly spelled in your `require()` statement.
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
js-yamlrequiredCore dependency for YAML serialization, used internally by `json-to-pretty-yaml` for its stringify method.
Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
json-to-pretty-yaml — npm install json-to-pretty-yaml · libregistry