← All Tools

Why the YAML→JSON Converter Fails on Kubernetes Manifests

Guide · Last verified Aug 27, 2026

If you've ever pasted an entire Kubernetes manifest into a YAML→JSON converter and gotten back an empty result with a cryptic error, the file probably isn't broken — the converter was likely just never designed to handle that kind of file in the first place. This guide walks through why Kubernetes YAML conventions clash with how a standard YAML parser behaves, and exactly how to use the YAML to JSON Converter so the conversion succeeds without errors, verified down to the code level.

1. Why Kubernetes packs multiple resources into one file

Kubernetes manifests commonly stuff several different resources — a Deployment, a Service, a ConfigMap — into a single YAML file. This is so related resources can be deployed as one unit with a single kubectl apply -f call, using YAML's own "---" document separator to chain multiple independent YAML documents together in one file. From the YAML spec's point of view, a file like this isn't "one document" — it's a "document stream." In other words, contrary to the intuitive assumption that one file equals one document, Kubernetes YAML is structured as N documents inside a single file.

2. What most YAML→JSON converters assume

A typical YAML→JSON converter is built on the assumption that "one file equals one top-level object." This site's own YAML to JSON Converter is no different — internally it uses the load() function from js-yaml (version 4.1.0), a JavaScript YAML parsing library. js-yaml separately provides load(), which parses a single document, and loadAll(), which parses an entire multi-document stream into an array. Since this tool is built to show one resulting object as JSON, it uses load(). The problem is that when load() receives a multi-document stream, it doesn't "process just part of it" — it throws an exception and aborts the conversion entirely.

What actually happens: paste a YAML file that chains two or more documents with "---", like a Kubernetes manifest, into the YAML to JSON Converter, and the result field stays empty while you get an error along the lines of YAML parse error: expected a single document in the stream, but found more. There's no "partial processing" that picks out just the first Deployment for you.

3. So how should you actually convert it

The fix is simple, if manual: split the file at each "---" separator and paste each document in one at a time to convert it.

SituationResult
Pasting the whole file with Deployment + Service joined by "---"Parse error, no result
Pasting just the Deployment sectionConverts successfully
Pasting just the Service sectionConverts successfully

If there are more resources, you'll need to repeat this once per resource. It's tedious, but it also means there's a clear, unambiguous rule for exactly where to cut each resource's YAML — right at the "---" line.

4. It also affects anchors (&) and aliases (*)

YAML supports anchor/alias syntax, letting you define a repeated value with &name and reuse it with *name. Within a single document, these get resolved into actual data and inlined directly into the resulting JSON. But that resolution only happens once load() has successfully parsed the document — and since multi-document YAML fails at the parsing stage to begin with, the conversion fails before anchor/alias resolution even becomes a question. If you were sharing an anchor across multiple resources in a Kubernetes manifest, keep in mind that splitting the document also breaks that shared relationship.

5. Practical tip: check whether you even need to convert

The usual reason to turn a Kubernetes manifest into JSON is to send it directly to the API server, or to process it with a JSON-based tool (jq, a policy checker, and so on). Since it's common to work with one resource at a time, if you're already managing your files split per resource, you'll never run into this error at all. If you do need to keep several resources in one file, it's worth building the habit of counting the "---" separators before pasting into the YAML to JSON Converter each time — that way the error message never catches you off guard. If you want to double-check the YAML syntax itself before converting, you can also re-validate the output afterward with the JSON Validator.

Frequently Asked Questions

Q. If I paste a multi-document YAML separated by "---", does it convert just the first document?

No. The js-yaml load() function this tool uses throws an error the moment it hits multi-document YAML, and the conversion fails entirely. It doesn't pick out the first document for you — the result field stays empty and you just get an error message.

Q. How do I convert a file with several resources chained together, like a Kubernetes manifest?

Pasting the whole thing in triggers a multi-document error, so you need to split the file at each "---" separator into individual documents and paste them in one at a time.

Q. Why doesn't it at least convert the first document?

The js-yaml load() function this tool uses is designed around the assumption that there's exactly one document, so it treats hitting a second "---" as an error condition in itself. That's different behavior from the loadAll() family of functions, which would return the first document among several.

Q. What happens to YAML anchors (&) and aliases (*) during conversion?

Within a single document, anchors and aliases get resolved into their actual values and inlined into the JSON. For multi-document YAML, parsing already fails before that resolution step is ever reached.