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 🙏

© 2026 – Pkg Stats / Ryan Hefner

schemascii

v1.1.0

Published

Convert JSON, JSONC, YAML, or XML file structure to ASCII directory tree

Readme

schemascii

Convert JSON, JSONC, YAML, or XML file structure to ASCII directory tree.

Installation

npm install schemascii

Or use it directly with npx:

npx schemascii <file>

Supports JSON, JSONC, YAML, and XML file formats.

Usage

CLI

# Output to stdout (JSON)
schemascii structure.json

# JSONC with comments
schemascii structure.jsonc

# YAML format
schemascii structure.yaml

# XML format
schemascii structure.xml

# Output to file
schemascii structure.json -o tree.txt

# Limit tree depth (using shorthand)
schemascii structure.json -d 2

# Custom characters (ASCII style, using shorthand)
schemascii structure.json -b "|" -c "'" -t "+" -H "-"

# Custom indent and root prefix (using shorthand)
schemascii structure.json -i 4 -r "myproject"

# Combine multiple options (using shorthand)
schemascii structure.json -d 3 -i 3 -r "project"

# Custom max depth indicator
schemascii structure.json -d 2 -m ">>>"
schemascii structure.json -d 2 -m "[more]"

CLI Options

All TreeOptions can be specified via command-line arguments (both long and short forms):

  • --root-prefix, -r <text> - Root prefix text to display at the top
  • --branch-char, -b <char> - Character for vertical branches (default: │)
  • --corner-char, -c <char> - Character for corner connectors (default: └)
  • --tee-char, -t <char> - Character for tee connectors (default: ├)
  • --horizontal-char, -H <char> - Character for horizontal lines (default: ─)
  • --indent-size, -i <number> - Number of spaces for indentation (default: 2)
  • --max-depth, -d <number> - Maximum depth to display (default: unlimited)
  • --max-depth-indicator, -m <text> - Text shown when max depth is reached (default: "...")
  • --output, -o <file> - Output file path (default: stdout)
  • --help, -h - Show help message

Programmatic API

import { schemaToTree, fileToTree } from 'schemascii';

// From object
const json = {
  "src": {
    "components": {},
    "utils": {
      "helpers": {}
    }
  },
  "tests": {}
};

const tree = schemaToTree(json);
console.log(tree);

// From file (auto-detects format: JSON, JSONC, YAML, or XML)
const tree = await fileToTree('structure.json');
const tree2 = await fileToTree('structure.jsonc');
const tree3 = await fileToTree('structure.yaml');
const tree4 = await fileToTree('structure.xml');
console.log(tree);

File Format

Each key in the object represents a directory. Nested objects represent nested directories. The tool supports JSON, JSONC (JSON with comments), YAML, and XML formats.

JSON Example

{
  "src": {
    "components": {
      "Button.tsx": {},
      "Input.tsx": {}
    },
    "utils": {
      "helpers": {
        "format.ts": {}
      }
    }
  },
  "tests": {
    "unit": {}
  }
}

JSONC Example (with comments)

{
  // Source code directory
  "src": {
    "components": {
      "Button.tsx": {},
      "Input.tsx": {}
    },
    "utils": {
      // Helper utilities
      "helpers": {
        "format.ts": {}
      }
    }
  },
  // Test files
  "tests": {
    "unit": {}
  }
}

YAML Example

src:
  components:
    Button.tsx: {}
    Input.tsx: {}
  utils:
    helpers:
      format.ts: {}
tests:
  unit: {}

XML Example

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <src>
    <components>
      <Button.tsx />
      <Input.tsx />
    </components>
    <utils>
      <helpers>
        <format.ts />
      </helpers>
    </utils>
  </src>
  <tests>
    <unit />
  </tests>
</root>

All formats produce the same output:

.
├── src
│   ├── components
│   │   ├── Button.tsx
│   │   └── Input.tsx
│   └── utils
│       └── helpers
│           └── format.ts
└── tests
    └── unit

Options

You can customize the tree output with options:

const tree = schemaToTree(json, {
  rootPrefix: 'project',
  branchChar: '│',
  cornerChar: '└',
  teeChar: '├',
  horizontalChar: '─',
  indentSize: 2,
  maxDepth: 3,  // Limit tree depth to 3 levels
  maxDepthIndicator: '...'  // Text shown when max depth is reached
});

Max Depth

You can limit the depth of the tree using the maxDepth option. When the maximum depth is reached, an indicator (default: ...) is shown to indicate that there's more content below. The depth is counted from the root level (depth 0), so maxDepth: 1 shows root items and their direct children, maxDepth: 2 shows up to grandchildren, etc.

You can customize the indicator text using the maxDepthIndicator option:

// Limit to 2 levels deep (root + 2 levels)
const tree = schemaToTree(deepStructure, { maxDepth: 2 });

// Custom indicator text
const tree = schemaToTree(deepStructure, { 
  maxDepth: 2, 
  maxDepthIndicator: '>>>' 
});

Example output with maxDepth: 2:

.
├── src
│   ├── components
│   │   ├── Button.tsx
│   │   └── Input.tsx
│   │       ...        // indicates more nested content
│   └── utils
│       └── helpers
│           ...        // indicates more nested content
└── tests
    └── unit
        ...

Example with custom indicator (maxDepthIndicator: '>>>'):

.
├── src
│   ├── components
│   │   ├── Button.tsx
│   │   └── Input.tsx
│   │       >>>        // custom indicator
│   └── utils
│       └── helpers
│           >>>        // custom indicator
└── tests
    └── unit
        >>>

License

MIT