YAML Truncator

Shrink an oversized YAML document down to a manageable size by capping nesting depth, array item counts, and individual string lengths, with a clear marker left everywhere something was cut, and the result stays valid, parseable YAML. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Some YAML documents, a full Helm chart's rendered output, a large exported manifest, are too big to usefully paste anywhere: a bug report, a chat message, a code review comment. This tool shrinks a document down to a representative, still-valid sample by capping how deep it nests, how many array items it keeps, and how long any single string can be.

Unlike simply cutting text at a character count, every truncation happens at a structural boundary, so the output always parses as valid YAML, just a smaller version of the original.

What Is YAML Truncator?

A YAML truncator applies three independent limits to a parsed document: a maximum nesting depth, a maximum number of items per array, and a maximum length per string scalar.

Anything past those limits is replaced with a clear marker (an ellipsis on strings, a summary count on arrays, or a `__truncated__` placeholder on deeply nested containers) rather than being silently dropped, so it's always visible that truncation happened and roughly how much was cut.

How YAML Truncator Works

The input is parsed into its value tree, then walked recursively while tracking depth. Strings longer than the limit are sliced and suffixed with an ellipsis. Arrays longer than the limit are sliced and get one extra entry describing how many items were cut. Mappings or arrays found past the depth limit are replaced entirely with a `__truncated__` marker string.

The truncated value is re-serialized with the same block-style YAML stringifier used by the formatter, so the result is always parseable regardless of how aggressive the limits are.

When To Use YAML Truncator

Use it before pasting a large YAML document into a support ticket, a Slack message, or a GitHub issue, when you only need to show the shape of the problem, not the entire file.

It's also useful for creating small, representative fixtures from a large real-world config for tests or documentation.

Features

Advantages

  • Guarantees valid, parseable YAML output regardless of how aggressive the limits are.
  • Leaves a visible marker at every truncation point instead of silently dropping data.
  • Three independent limits (depth, array length, string length) let you target exactly what's making a document unwieldy.
  • Runs entirely client-side, so large or sensitive documents never leave your browser.

Limitations

  • Truncation is lossy and one-directional; there is no way to reconstruct the original from the truncated output.
  • Comments are dropped as a side effect of the parse-and-reserialize round trip, the same as every other tool in this category.
  • The `__truncated__` marker replaces an entire nested container at once; there's no partial truncation of a mapping's keys at the same depth level, only its descendants beyond the depth limit.

Examples

Capping a long string

Input

bio: A very long biography that goes on for a very long time indeed.

Output

bio: A very long biography that goes on for…

The string is cut at the configured max length and suffixed with an ellipsis.

Capping array length

Input

items:
  - 1
  - 2
  - 3
  - 4
  - 5

Output

items:
  - 1
  - 2
  - "…truncated 3 more item(s)…"

With a max of 2 items, the remaining three are summarized in a single marker entry.

Best Practices & Notes

Best Practices

  • Start with a generous depth and item limit and tighten them until the output is a manageable size, so you don't cut more than necessary.
  • Use a low string length limit specifically when the problem is a handful of very long values (like base64 blobs) bloating an otherwise small document.
  • Keep the original file alongside any truncated version you share, since truncation is not reversible.

Developer Notes

Depth is counted from the outermost mapping/sequence at 0; a `maxDepth` of 3 keeps three levels of nested containers and replaces anything beyond that with the marker. String truncation, array truncation, and depth truncation are independent and can all apply to the same document simultaneously, since the walk checks all three conditions on each value it visits.

YAML Truncator Use Cases

  • Trimming a large config down to a shareable size for a bug report or support request
  • Producing a small, representative fixture from a large real-world YAML file for tests
  • Redacting or shortening long string values (tokens, blobs) while keeping the surrounding structure intact
  • Getting a quick sense of a huge document's shape without loading the whole thing into an editor

Common Mistakes

  • Setting the depth limit too low and losing the exact section of the document you meant to show.
  • Forgetting that truncation is lossy and overwriting the only copy of the original document with the truncated version.
  • Expecting `__truncated__` markers to indicate how much was cut, unlike the array marker, the depth marker doesn't report a size, only that something was there.

Tips

  • Run YAML Statistics first to see actual depth and array sizes, so you can set limits that cut exactly what you intend.
  • Combine with YAML Minifier afterward if you also want the truncated output as compact as possible.
  • If you need the full document but a smaller one for a specific section, Extract Keys or Extract Values may be a better fit than truncation.

References

Frequently Asked Questions