This turns JSON into indentation-based YAML. Braces and most quotes disappear, which makes the result easier to maintain by hand as a config file, and key order stays exactly as in the source JSON.
It helps when you move a resource fetched with kubectl get -o json into a manifest, or paste settings received from an API into docker-compose.yml, application.yml or a GitHub Actions workflow.
JSON box. Invalid syntax shows JSON parsing failed in the result; run it through the JSON validator first if needed.Result. Indentation is two spaces.{
"services": {
"web": {
"image": "nginx:1.27",
"ports": ["8080:80"],
"environment": { "FEATURE_FLAG": "on", "GREETING": "hello\nworld" }
}
}
}services:
web:
image: nginx:1.27
ports:
- 8080:80
environment:
FEATURE_FLAG: "on"
GREETING: |-
hello
world
The string "on" keeps its quotes: written bare as on, a YAML 1.1 parser would read it as boolean true. GREETING contains a newline, so it is emitted as a |- block that shows each line as written.
yes, no, on, off, y, n, ~, null, and look-alikes such as "0777", "1.0" or "2024-01-01", are quoted so PyYAML (1.1) and modern 1.2 parsers read the same value.22:22, which YAML 1.1 can read as a base-60 number, are quoted too, avoiding a classic docker-compose port-mapping bug.|- literal blocks.[] and {}.Convert a Deployment or ConfigMap pulled from the cluster as JSON, delete fields like status and metadata.uid, and you have a manifest ready for Git.
A block of properties received as JSON from a config server or docs becomes a YAML hierarchy, so you don't have to indent keys like spring.datasource.url by hand.
&) or aliases (*) are generated; an object repeated in the JSON is repeated in the YAML.---, convert each resource and join them yourself.Quotes are added only where a bare value would be read as another type. nginx:1.27 is a string either way, but on, 010 and 22:22 turn into booleans or numbers in some parsers, so they get quoted.
The structure is valid as is. Output from kubectl get -o json carries server-populated fields such as status, resourceVersion and managedFields, though, and those are best removed before applying.
There is no option; it is fixed at two spaces, the convention used throughout Kubernetes, docker-compose and GitHub Actions documentation.