Home Text Tools Math & Numbers Developer Tools Date & Time Image Tools Blog
JSON to YAML Converter

Convert kubectl JSON Output to YAML for Kubernetes Manifests

Turn JSON from kubectl or an API into YAML you can edit and apply, and learn which fields to remove before committing it.

You ran kubectl get deployment my-app -o json and now want a manifest you can edit and keep in Git. Kubernetes accepts JSON, but nearly every team writes manifests in YAML because it is shorter and easier to read. Converting the output is quick; knowing what to clean up afterwards is the useful part.

JSON to YAML Converter FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool

Convert, then tidy

Paste the JSON into the JSON to YAML Converter and copy the result. The structure is identical: objects become mappings, arrays become lists with a dash, and strings are written without quotes unless they need them.

What you get is a snapshot of a live object, not a clean source manifest. The cluster adds fields that you should not commit.

A good habit is to keep the converted file under version control from the first moment. Make one commit with the raw conversion and another with your cleanup, so reviewers can see exactly what you removed and why. It also makes it easy to roll back if a deleted field turns out to matter.

Steps

Do not forget the apiVersion and kind lines at the top. kubectl output includes them, but if you assembled the JSON by hand from a fragment, the manifest will be rejected without both. Likewise, a List wrapper appears when you fetch several objects at once, and you will want to split it into separate documents separated by three dashes.

  1. Run kubectl get <resource> <name> -o json and copy the output.
  2. Paste it into the converter and copy the YAML.
  3. Save it as a file such as deployment.yaml.
  4. Remove the cluster-generated fields listed below.
  5. Check indentation and any multiline strings.
  6. Validate it with kubectl apply --dry-run=client -f deployment.yaml before committing.

Fields to remove

Live objects carry status, bookkeeping metadata and defaults that the API server filled in. Leaving them in makes your manifest noisy and can cause conflicts when you apply it to another cluster.

Delete the following before you reuse the file:

  • The entire status block.
  • metadata.uid, resourceVersion, generation and creationTimestamp.
  • metadata.managedFields, which can be very long.
  • The kubectl.kubernetes.io/last-applied-configuration annotation.
  • For Services, an allocated clusterIP if you want a new one in the target cluster.
  • Any deployment.kubernetes.io/revision annotation.

YAML details that cause errors

YAML uses spaces for indentation and forbids tabs. A tab pasted from somewhere else will break the file. Keep a consistent two spaces per level, which is the usual Kubernetes style.

Some values look like other types. The strings yes, no, on and off may be read as booleans by some YAML 1.1 parsers, and a version like 1.20 can turn into a number, losing the trailing zero. The converter does not add quotes to words like yes or to a version like 1.20, so add quotes yourself where the value must stay text.

ConfigMap data deserves care too. Multi-line values are often written by hand with a block scalar using a pipe character, where the indentation inside the block is part of the content. The converter writes a string with line breaks as a quoted string with escape sequences, so rewrite config files or scripts stored this way as block scalars if you want them readable.

Secrets

If your JSON came from a Secret, the values are base64 encoded, not encrypted. Do not paste real secrets into any shared tool or commit them to a repository. Use a secrets manager or sealed secrets, and keep only placeholders in the YAML you store in Git.

Finish by diffing the cleaned YAML against what is running with kubectl diff -f. If the only differences are the fields you intentionally removed, the manifest is a faithful description of the object, and applying it will not surprise anyone.

Try the free JSON to YAML Converter
Runs in your browser. No sign-up, nothing to install.

Comments (0)

No comments yet. Be the first to share a thought.