JSON to Pretty YAML Converter

1.2.2 · abandoned · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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);

view raw JSON →