Type inference is the whole story
Under the default YAML 1.2 core schema, true and false are booleans, null and a tilde represent null, and numeric forms become numbers. Bare yes, no, on and off remain strings. ISO-looking dates normally remain strings too. The rule is not “everything without quotes is a string except digits”; YAML has a defined schema with several scalar spellings.
Quote identifiers and versions when their spelling is data. The default parser reads 0755 as decimal 755, whereas 0o755 is octal 493. A version written as 1.10 becomes 1.1. The converter cannot recover whether that number once had a trailing zero, so fix the YAML before conversion.
The result also passes through JavaScript values and JSON.stringify. Huge integers and precise decimals can round. YAML non-finite numbers such as .inf and .nan become JSON null, because JSON serialization has no finite numeric representation for them. Ordinary structural comparisons cannot recover those original scalars.
country: NO
enabled: on
version: 1.10
code: "0755"
mode: 0755
permissions: 0o755{
"country": "NO",
"enabled": "on",
"version": 1.1,
"code": "0755",
"mode": 755,
"permissions": 493
}| Input scalar | Default JSON value | Review decision |
|---|---|---|
| yes / no / on / off | string | Other YAML versions may disagree |
| "1.10" / 1.10 | "1.10" / 1.1 | Quote versions |
| .inf / .nan | null | Replace unsupported numbers deliberately |
| 0755 / 0o755 | 755 / 493 | Quote identifiers; distinguish bases |
What has no JSON equivalent
Comments, anchor names, formatting style and tag syntax are not represented in JSON. Supported tags influence the parsed value before their syntax disappears; this converter does not register application-specific custom tag handlers. Keep the YAML source if comments or tags document something beyond the resulting value.
Ordinary aliases reuse a parsed value, which JSON serialization writes out at each use. This can make the result larger. Alias expansion is limited with maxAliasCount set to 100; that is a library protection against excessive expansion, not a promise that any document containing fewer than one hundred visible aliases will succeed.
A cyclic alias graph cannot be serialized as JSON and is rejected. Non-string mapping keys must become object property names, so their type identity is not preserved. The processor’s non-string-key warning is heuristic: it looks at numeric or boolean-looking property names after conversion and is not proof that every problematic source key was detected.
Multi-document files
A YAML stream can contain several documents separated by document markers. A single leading --- is normal and does not make a stream multi-document; another actual document is what matters. Kubernetes bundles commonly contain multiple resources this way.
The converter rejects multiple documents through the library’s single-document parser. It does not take the first document, even though an old internal warning string mentions that possibility. There is no option to automatically return an array of documents.
Split resources deliberately and convert each separately. If the target expects one array, assemble a YAML sequence or JSON array with that agreed schema. Do not blindly split every line beginning with dashes: use a proper YAML-stream parser for automated processing, and keep document boundaries separate from content inside scalars.
---
name: first
---
name: secondDuplicate keys and merge keys
The library rejects duplicate mapping keys by default. Repeating timeout twice in one mapping is an error, not a last-value-wins override. Correct the source so each local key appears once; a failed parse produces no JSON to compare.
Merge keys are different. The << syntax is a YAML 1.1 extension, not part of the YAML 1.2 core schema. This processor explicitly sets merge: true, so supported merges are expanded, with local properties overriding merged defaults. That behavior is a configured feature here, not a universal rule to assume in another YAML 1.2 parser.
A merge source can supply several defaults, which can obscure where the final setting came from. Review the referenced mapping and local overrides together. The resulting JSON contains values, not provenance: after conversion you cannot tell whether retries was inherited or written locally.
defaults: &base
retries: 2
enabled: true
job:
<<: *base
retries: 5timeout: 10
timeout: 30Verifying the conversion
Directives can affect interpretation before they disappear. An explicit %YAML 1.1 directive selects YAML 1.1 behavior, so bare NO can become false even though it is a string under the usual defaults. %TAG establishes tag-handle notation; it does not add a custom application tag implementation to this converter.
The processor adds its directive warning when it sees a %YAML line. A %TAG-only document does not necessarily trigger that warning. Neither directive has a JSON representation, so absence of a warning is not evidence that all YAML authoring information survived.
Verify the output types, not just whether conversion completed. Check quoted identifiers, nulls, version strings and expected booleans. Validate against a schema or the destination application for required fields and allowed values; syntax conversion cannot decide whether the configuration is useful or safe for that application.
%YAML 1.1
---
country: NO- Confirm the intended YAML version and inspect directives.
- Resolve duplicate-key and multi-document errors in the source.
- Check types and values after merge expansion.
- Keep the original YAML when comments, aliases or tags matter.
- Validate the JSON against the destination schema.
YAML 1.2.2 specification — Primary reference for documents, directives and core scalar resolution.
yaml library parsing options — Library behavior for version selection, duplicate keys, merges and alias limits.