npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

smart-json2md

v1.0.0

Published

Convert plain JSON files to hierarchical Markdown documents with intelligent structuring

Readme

smart-json2md

A simple utility to convert plain JSON files to hierarchical Markdown documents with intelligent structuring.

Features

  • Automatically converts JSON objects to Markdown with headings based on hierarchy
  • Supports nested objects with appropriate heading levels
  • Handles deep structures by converting to lists when exceeding configured heading levels
  • Arrays are displayed as Markdown lists
  • Intelligently processes arrays of objects with common structure
  • Configurable minimum and maximum heading levels
  • Option to use ordered or unordered lists for deep structures
  • Option to include type information for values
  • Easy to use CLI and programmatic API

Installation

npm install smart-json2md

Or globally:

npm install -g smart-json2md

CLI Usage

smart-json2md input.json -o output.md

Options

Usage: smart-json2md [options] <input>

Convert JSON files to Markdown with automatic hierarchy

Arguments:
  input                  Input JSON file path

Options:
  -V, --version          output the version number
  -o, --output <output>  Output Markdown file path
  -t, --types            Include type information
  -l, --max-level <level>  Maximum heading level (1-6) (default: "6")
  -m, --min-level <level>  Minimum heading level (1-6) (default: "1")
  -n, --no-process-arrays  Disable intelligent array processing
  -p, --pretty           Make output more readable with extra spacing
  -r, --ordered-lists    Use ordered lists for content beyond max heading level
  -h, --help             display help for command

Programmatic Usage

import { jsonToMarkdown, convertJsonFileToMarkdown } from 'smart-json2md';

// Convert a JSON object directly
const json = {
  person: {
    name: 'John Doe',
    age: 30,
    address: {
      street: '123 Main St',
      city: 'Anytown',
      location: {
        latitude: 40.7128,
        longitude: -74.0060,
        details: {
          region: 'Northeast',
          country: 'USA'
        }
      }
    },
    hobbies: ['reading', 'hiking', 'coding'],
    contacts: [
      { type: 'email', value: '[email protected]' },
      { type: 'phone', value: '555-1234' }
    ]
  }
};

// Basic conversion
const markdown = jsonToMarkdown(json);
console.log(markdown);

// Advanced options
const advancedMarkdown = jsonToMarkdown(json, {
  minHeadingLevel: 2,      // Start with h2 headings instead of h1
  maxHeadingLevel: 4,      // Only use headings up to h4
  includeTypes: true,      // Include data types
  useOrderedLists: true,   // Use numbered lists for deep structures
  processArrayObjects: true // Enabled by default
});
console.log(advancedMarkdown);

// Convert a file
await convertJsonFileToMarkdown('input.json', 'output.md', {
  minHeadingLevel: 1,
  maxHeadingLevel: 4,
  useOrderedLists: true
});

Example: Deep Structure Handling

Given a deeply nested JSON:

{
  "level1": {
    "level2": {
      "level3": {
        "level4": {
          "level5": {
            "level6": {
              "level7": "This is very deep"
            }
          }
        }
      }
    }
  }
}

With maxHeadingLevel: 4 and useOrderedLists: true, the result will be:

# level1

## level2

### level3

#### level4

1. **level5**:
  
  1. **level6**:
    
    1. **level7**: This is very deep

Notice how levels beyond the 4th (max heading level) automatically convert to ordered lists.

Advanced Options

The library provides several options for customizing the conversion:

  • minHeadingLevel: Starting heading level (1-6, default: 1)
  • maxHeadingLevel: Maximum heading level (1-6, default: 6)
  • includeTypes: Add type information for values
  • processArrayObjects: Enable smart processing of arrays containing objects
  • useOrderedLists: Use numbered lists instead of bullet points for deep structures
  • valueFormatter: Custom function to format specific values

License

MIT