Skip to content
BCBinary Code Translator
Menu

Data utility

JSON to YAML Converter

Convert JSON and YAML in either direction with the existing js-yaml library, a restricted JSON-compatible schema and explicit checks for dangerous object keys, unsupported values and cyclic aliases.

Conversion happens locally. YAML is parsed as data, not as executable JavaScript, and custom JavaScript tags are rejected.

How to convert JSON and YAML safely

Select the direction, paste the source document and run the conversion. The YAML side intentionally supports only JSON-compatible scalar, sequence and mapping values. That narrower behavior avoids JavaScript-specific tags and makes the result predictable for APIs and configuration pipelines.

  1. Choose JSON to YAML when you want a more human-oriented configuration representation, or YAML to JSON for APIs and tooling.
  2. Paste one complete document. JSON must be valid; YAML must use the restricted safe schema supported by this page.
  3. Convert and inspect the result. Nested mappings and arrays are preserved, while aliases are expanded into normal JSON data when they are acyclic.
  4. Review warnings for unsafe JSON integers and errors for blocked keys, custom tags, cycles or unsupported values before copying.

Examples and expected behavior

Input Output Notes
{"name":"api","ports":[80,443]} name: api ports: - 80 - 443 Objects become mappings and arrays become YAML sequences.
enabled: true retries: 3 { "enabled": true, "retries": 3 } JSON-compatible booleans and numbers preserve their basic types.
message: 你好 👋 {"message":"你好 👋"} Unicode strings remain Unicode in both formats.
date: 2026-07-29 {"date":"2026-07-29"} Under the restricted schema, date-like text remains a string instead of becoming a Date object.
payload: !!js/function function(){} Rejected YAML JavaScript-specific tags are not permitted by the selected schema.
__proto__: polluted: true Rejected dangerous key Prototype-related keys are blocked before a JSON object is produced.

Supported data model and schema choice

The converter deliberately uses js-yaml with JSON_SCHEMA rather than the broader default YAML schema. Supported values are the same fundamental values JSON understands: mappings with string keys, sequences, strings, finite numbers, booleans and null. This keeps the output suitable for typical API payloads and avoids automatic construction of dates, binary objects, regular expressions or JavaScript-specific values.

YAML is a much larger language than JSON, so not every valid YAML document is accepted here. Custom tags, implementation-specific types and values that cannot be represented reliably in JSON are rejected. This is a design boundary, not a parser defect. If a deployment system relies on specialized tags, use that system’s own parser and review its security model rather than expecting a general web converter to interpret them.

  • Mapping keys must be strings for JSON output.
  • Non-finite numbers, functions, symbols and undefined are not supported.
  • Date-looking scalars remain plain strings under the JSON-compatible schema.

Mappings, sequences, aliases and ordering

JSON objects map naturally to YAML mappings, and JSON arrays map to YAML sequences. Property order is preserved as provided by the JavaScript object model, but neither format should be used when semantic meaning depends on key order. When converting YAML aliases, the parser may create shared references. The converter walks the result and produces ordinary JSON-compatible values while detecting cycles.

Acyclic reuse can be represented in the resulting JSON only by duplicating the referenced value, because JSON has no alias syntax. A self-reference or mutually recursive alias graph cannot be serialized as JSON and is rejected as a cyclic alias. JSON to YAML output disables reference generation, so repeated objects are emitted independently instead of introducing anchors that may surprise another parser.

  • Aliases are a YAML feature, not a JSON feature.
  • Cyclic graphs are rejected before JSON.stringify.
  • Key order is presentation detail unless a consuming specification explicitly says otherwise.

Prototype pollution and dangerous keys

Keys named __proto__, prototype or constructor can be hazardous when untrusted data is merged into ordinary JavaScript objects by vulnerable application code. The converter blocks these names anywhere in a parsed mapping and rebuilds mappings with a null prototype before serialization. This prevents the conversion step from creating inherited properties or mutating Object.prototype.

Blocking these keys here is defense in depth, not a substitute for secure handling in the application that ultimately consumes the data. A later system might parse the copied output differently, merge it unsafely or allow equivalent attack paths through other fields. Treat configuration and data imports as untrusted, validate an explicit schema and avoid recursive merge utilities that copy arbitrary keys into privileged objects.

  • Do not blindly merge parsed configuration into application defaults.
  • Validate allowed property names and types at the destination.
  • Keep dependencies such as YAML parsers patched and review security advisories.

Common conversion uses

Teams often convert JSON API examples into YAML for documentation, Kubernetes-adjacent configuration drafts, CI settings or human review. The reverse direction helps when an API accepts JSON, a test fixture requires JSON or a debugging tool cannot read YAML. The converter is also useful for demonstrating how indentation, sequences and mappings correspond between the two syntaxes.

For production configuration, conversion is only one step. Review comments that may be lost, confirm quoting rules, validate against the target product’s schema and test the output with the exact software that will consume it. Some YAML processors implement different schema versions or implicit typing rules, so a value that looks identical on screen may be interpreted differently elsewhere.

  • Prepare an API request from a YAML draft.
  • Turn a JSON response sample into readable documentation.
  • Inspect whether a scalar is a string, number, boolean or null.
  • Remove YAML-only aliases before moving data into a JSON-only system.

Errors and compatibility boundaries

JSON errors are reported before YAML emission. YAML errors include malformed indentation, invalid quoting, unsupported tags, dangerous keys, unsupported value types and cyclic aliases. Tabs in indentation, ambiguous colons, missing spaces after mapping separators and incorrectly aligned sequence markers are frequent causes. Fix the first structural error and convert again.

The page does not preserve YAML comments, anchor names, scalar style, document directives or exact whitespace when converting through the JSON data model. Multiple YAML documents separated by --- are not treated as one JSON value. Merge keys and schema-specific implicit types may also behave differently from a product-specific parser. Use this tool for JSON-compatible data interchange, not as a byte-preserving YAML formatter.

  • Comments are not represented in JSON and are lost.
  • Specialized tags such as !!js/function are rejected.
  • Always test generated configuration with the target application before deployment.

Security, privacy and resource limits

Parsing and serialization happen in the browser tab. The tool does not intentionally send documents to an external service or persist them in browser storage. The YAML parser is configured for a restricted schema, and the post-parse walk rejects dangerous keys, unsupported objects and cycles. No evaluated JavaScript types are enabled.

Large alias graphs can consume substantial memory even without code execution, and deeply nested inputs can stress the browser. Do not paste unbounded attacker-controlled files into a privileged workstation. Local processing also does not protect content from screen capture, clipboard history or extensions. Remove credentials and private configuration values before sharing converted output.

  • Use size limits when accepting YAML in your own applications.
  • Do not treat YAML as safe merely because it is text.
  • Keep secrets out of screenshots, issue trackers and copied examples.

How this differs from formatters and CSV tools

A JSON formatter changes whitespace but keeps the JSON serialization. This converter changes the serialization language and therefore cannot preserve JSON text byte for byte. A JSON to CSV converter expects tabular records and must choose headers and a strategy for nested values; YAML can represent the complete nested JSON-compatible structure without flattening it.

Use a product-specific YAML validator when features such as custom tags, multi-document streams or merge semantics are required. Use a schema validator when the question is whether fields are allowed, not merely whether syntax parses. Use the JSON formatter first when malformed JSON is the only issue. Selecting the narrowest tool makes errors easier to interpret and avoids accidental semantic changes.

Frequently asked questions

Is YAML conversion safe from code execution?

This implementation uses js-yaml with JSON_SCHEMA and does not enable JavaScript-specific tags. It then walks the parsed value and rejects dangerous keys, unsupported values and cycles. No parser setting can make arbitrary downstream use automatically safe, so validate copied data again at its destination.

Why does a date in YAML become a JSON string?

The restricted JSON-compatible schema intentionally avoids constructing Date objects. A value such as 2026-07-29 remains text, which is more predictable for JSON interchange. A product-specific YAML parser using another schema may interpret the same scalar differently.

Are YAML comments preserved?

No. Comments, scalar style and exact whitespace are presentation features that do not exist in the JSON data model. Once YAML is parsed into JSON-compatible values, that information is unavailable for the reverse conversion.

What happens to YAML anchors and aliases?

Acyclic aliases can be represented only by repeating the referenced data in JSON. Cyclic aliases cannot be serialized to JSON and are rejected. JSON to YAML output disables generated references, so it does not introduce anchors.

Why are __proto__ and constructor rejected?

Those names are commonly involved in prototype-pollution vulnerabilities when untrusted objects are merged unsafely. Blocking them reduces risk during conversion, though the receiving application still needs its own schema validation and safe object handling.

Can I use the output directly as production configuration?

Treat it as a draft. Validate it with the exact application, schema and YAML implementation that will consume it. Product-specific tags, implicit typing, multi-document files and comments may not survive this JSON-compatible conversion.

Related Developer Tools

View all tools

Cookie Preferences

Manage your cookie preferences. Necessary cookies cannot be disabled.

Necessary

Required

Required for language selection, privacy choices, and basic site functionality.

Cookies: NEXT_LOCALE

Analytics

Optional analytics cookies help us understand traffic and improve the website.

Cookies: _ga, _gid, _gat, _clck, _clsk

Advertising

Optional advertising cookies may be used to show relevant ads and measure performance.

Cookies: __gads, _gcl_au, IDE