All Tools View Categories About Contact Privacy

Truncate YAML

Truncate nested YAML strings and arrays to controlled limits.

Processing is performed locally in this browser.

About Truncate YAML

Truncation is different from ordinary editing because the purpose is to reduce a document according to repeatable rules. This tool recursively visits the parsed YAML value and applies two limits: a maximum number of elements kept in every array and a maximum number of characters kept in every string. The surrounding object structure remains intact. A long description can therefore become a compact preview while a large list of servers becomes a shorter representative list without manually editing each nested branch.

The limits are intentionally global. This makes the operation useful when you are preparing a fixture with a predictable ceiling, generating a compact example for documentation, or reducing a configuration before pasting it into a ticket. Strings longer than the chosen length receive an ellipsis so readers can tell that the value was shortened. Arrays are sliced from the beginning rather than sampled randomly, which makes repeated runs deterministic and easier to compare.

The transformation is type-aware. Numbers stay numbers, booleans stay booleans, nulls stay null, and nested mappings are visited recursively. That matters because a careless text-only truncation could turn a numeric port into a string or corrupt structural punctuation. Empty arrays and objects remain structurally valid. The simplified YAML model does not preserve comments or advanced YAML constructs, so this feature is intended for ordinary configuration data and test fixtures rather than round-tripping every YAML language feature.

A practical workflow is to start with a generous string limit, such as 120 characters, and an array limit of 10. Inspect the output, then lower the limits until the fixture is compact enough for its destination. Be careful with data where the first array elements are not representative; slicing always keeps the first elements. Also remember that truncation changes the data. It should not be used to produce a production configuration or a security-sensitive authorization file unless the downstream consumer explicitly expects the shortened form.

Everything is processed in the browser and the result can be copied or downloaded immediately. Empty or malformed input is rejected. Because the parser holds the source and transformed structures in memory, extremely large documents can still be limited by browser resources. For normal configuration files, however, recursive traversal is straightforward and deterministic, making this tool a convenient way to create smaller examples while preserving the original hierarchy.

The safest use of truncation is for examples, previews, and test fixtures where losing detail is intentional. It is not a general-purpose compression format. The tool always keeps the first array elements rather than sampling randomly, so the result is deterministic and easy to compare. Choose the array limit with the meaning of the list in mind.

String limits are particularly useful for documentation. Long descriptions, URLs, embedded templates, or generated messages can dominate an example even when the surrounding structure is small. Adding an ellipsis makes the shortened value obvious. If exact values matter to a test, do not truncate that fixture; use a separate presentation copy instead.

Because truncation is recursive, nested lists and strings are handled even when they appear several levels below the root. This matters for service manifests that place metadata inside each item. A top-level-only implementation would leave the heaviest parts untouched and make the size control unpredictable. Here the same limits are applied consistently throughout the parsed tree.

Setting a limit to zero is a deliberate edge case. A zero array limit produces empty lists, while a zero string limit leaves only the ellipsis for non-empty strings. That can be useful for testing downstream handling of missing detail, but it also shows why the tool should not be used blindly on production configuration. Review the resulting YAML before exporting it.

The transformed data remains typed for non-string values. A numeric port stays numeric and a boolean remains a boolean, which avoids a common class of corruption caused by text substitution. The parser still operates within the supported YAML subset, so advanced YAML language features are outside the guarantee. For sample generation, that is usually a reasonable trade-off.

For sensitive documents, perform the truncation locally and keep the original file unchanged. The browser never uploads the YAML. The main resource cost is the parsed object plus the transformed object, so memory use grows with input size. For normal configuration files, recursive truncation is inexpensive and predictable.

Features

  • Recursive strings: Long strings are shortened wherever they appear in the nested structure.
  • Recursive arrays: Lists are sliced to a configurable maximum length at every depth.
  • Visible truncation: Shortened strings receive an ellipsis so the change is obvious.
  • Typed values preserved: Numbers, booleans, and null values are not converted to text.
  • Global limits: One set of limits applies consistently throughout the document.
  • Nested support: Objects inside arrays and arrays inside objects are traversed.
  • Preview stats: See how much text and list content remains.
  • Safe local operation: The transformation never uploads the YAML.

How to Use

  1. Paste the YAML document you want to shorten.
  2. Set the maximum string length and maximum array length.
  3. Click Truncate YAML to process every nested value recursively.
  4. Review the output and notice the ellipsis added to shortened strings.
  5. Check the before-and-after statistics.
  6. Copy or download the truncated YAML for fixtures or previews.

Examples

Example 1 — Short string. A 60-character value with a 20-character limit becomes visibly abbreviated.

name: very-long-applic…

Example 2 — Long list. A list of five servers with a limit of three keeps the first three.

servers:
  - api
  - worker
  - scheduler

Example 3 — Nested string. A description under metadata is truncated just like a top-level string.

metadata:
  description: compact preview…

Example 4 — Typed number. Ports remain numeric.

port: 8080

Example 5 — Zero array limit. Setting the array limit to zero produces empty arrays.

servers: []

Benefits

  • Compact fixtures: Reduce sample data for documentation and tests.
  • Preview generation: Create smaller examples without editing every branch manually.
  • Payload shaping: Keep configuration demos under a target size.
  • Readable output: Long values are visibly shortened rather than silently cut.
  • Consistent limits: Apply the same rules across a complex document.
  • Quick iteration: Try different limits without leaving the page.

Frequently Asked Questions

Does this tool upload my data?
No. The conversion logic is embedded in the page and processes the supplied text locally in the browser.
What happens with empty input?
The tool reports that the input is empty and does not create a misleading output file.
Can I copy the result?
Yes. The Copy action uses the browser clipboard when available and includes a local fallback.
Can I download the result?
Yes. Download creates the relevant file locally from the generated output.
How is invalid input handled?
The parser reports a clear error instead of silently producing a partial conversion.
Are comments preserved?
Comments are not retained once the YAML is parsed into a data structure, unless a feature specifically works on raw text.
What about nested data?
Nested mappings and sequences are traversed recursively, with format-specific rules documented on this page.
Does the tool require an external API?
No. The implementation is browser-only and has no fetch, XHR, WebSocket, or conversion service dependency.
Is the output guaranteed to be reversible?
No. Flat interchange formats can discard distinctions that YAML can represent.
Can large documents be processed?
Reasonable documents are supported, but browser memory and CPU still limit extremely large inputs.