Utvikling · verktøy

JSON til YAML-konverterer

Velg retning, lim inn en konfigurasjon og få resultatet klart til kopiering eller nedlasting.

Kjøres i nettleseren. Ingen opplasting.

YAML comments and formatting are not preserved when converting to JSON.

Om verktøyet

JSON til YAML-konverterer sem complicação.

Konverter JSON-objekter og -matriser til lesbar YAML, eller analyser YAML til formatert JSON. Konvertereren bruker et trygt, JSON-kompatibelt YAML-skjema og begrenser aliaser. YAML-kommentarer, ankere og opprinnelig formatering kan ikke bevares i JSON-utdata; alt behandles i nettleseren.

Veiledning

Slik bruker du JSON til YAML-konverterer

The JSON to YAML Converter turns JSON text into readable YAML, or reads YAML and shows it as indented JSON. You choose a direction, paste up to 500,000 characters, press Convert, then copy the result or download it as a file. It suits configuration files and small data sets. It cannot keep YAML comments, anchors or the original layout when the output is JSON.

Slik gjør du

  1. Pick JSON to YAML or YAML to JSON with the two buttons above the boxes. Switching direction empties the output box but keeps the text you typed in the input box.
  2. Paste your text into the input box. It cannot be empty and it can be at most 500,000 characters long, otherwise the tool shows a message instead of converting.
  3. Press Convert. The converted text fills the output box. If the text is not valid, a message points you to brackets, commas, quotes or indentation.
  4. Press Copy result, or Download result to save converted.yaml or converted.json. Clear empties both boxes.

Eksempler

JSON to YAML

Du skriver inn
Retning
JSON to YAML
Tekst
{"name":"UsefulVerse","fast":true,"tags":["a","b"],"nested":{"n":1.5,"empty":[],"none":null}}
Du får
YAML
name: UsefulVerse fast: true tags: - a - b nested: n: 1.5 empty: [] none: null

Objects become indented keys and lists become dash items. Order is kept as written. Empty lists show as [] and null stays null.

Kjørt med verktøyets egen kode.

Comments and anchors do not survive

Du skriver inn
Retning
YAML to JSON
Tekst
# server settings base: &b port: 80 copy: *b
Du får
JSON
{ "base": { "port": 80 }, "copy": { "port": 80 } }

The comment line is dropped. The anchor &b and its alias *b are replaced by two full copies of the same data, because JSON has no way to point back to an earlier value.

Kjørt med verktøyets egen kode.

Plain words stay text

Du skriver inn
Retning
YAML to JSON
Tekst
date: 2001-12-14 flag: yes empty: n: ~ hex: 0x1F
Du får
JSON
{ "date": "2001-12-14", "flag": "yes", "empty": null, "n": null, "hex": 31 }

The converter reads YAML with a JSON-compatible set of rules. A date stays a string and the word yes stays a string. An empty value and ~ become null, and 0x1F is read as the number 31.

Kjørt med verktøyets egen kode.

Two documents in one file

Du skriver inn
Retning
YAML to JSON
Tekst
a: 1 --- b: 2
Du får
Melding
Invalid JSON or YAML. Check indentation, quotes and data types.

The line of three dashes starts a second YAML document. The converter expects a single document and refuses the text. Convert each document on its own.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Turn a JSON settings file into YAML for a tool that reads YAML, such as a build or deployment file.
  • Turn YAML into JSON to feed it to a script, an API or a test that expects JSON.
  • Check how a small YAML snippet is understood by looking at the JSON it becomes.
  • Make a long JSON example easier to read in documentation by showing it as YAML.

Begrensninger

  • Input must not be empty and can have at most 500,000 characters. YAML with more than one document, or with a tag the JSON-compatible rules do not know, is refused.
  • Going to JSON drops YAML comments, expands anchors and aliases into copies and ignores formatting. The YAML and the JSON are the same data and no longer the same text.
  • In the YAML output, a string such as yes or on is written without quotes. Some older YAML tools treat those words as true or false, so add quotes by hand when the file is read by such a tool.
  • The error messages are general. They tell you whether the text looks like a JSON or a YAML problem, but not the line or character where it went wrong.

Tips

  • Convert there and back once, and compare the result with your start. Differences show what the conversion changed.
  • Keep your comments in the original YAML file. Use the converter for copies, not as the only place the file lives.
  • Quote version numbers like 1.10 in your JSON as strings. The converter then keeps them as text and does not turn them into the number 1.1.

Kilder

Vanlige spørsmål

Sobre JSON til YAML-konverterer.

How do I convert JSON to YAML?

Choose JSON to YAML, paste valid JSON into the input box and press Convert. The YAML appears in the output box. Press Copy result to copy it, or Download result to save it as converted.yaml.

Are YAML comments kept when I convert to JSON?

No. JSON has no comments, so they are removed. Anchors and aliases are also replaced by full copies of the data, and the original line breaks and spacing are not kept. Keep the YAML file if you need those.

Is my text uploaded to a server?

No. The conversion happens in your browser. The first time you convert, the page loads a small parsing library from this site, but the text you paste stays on your device and is not sent anywhere.

Why did my number or date change type?

YAML guesses types from plain text. With the rules used here, 0x1F becomes the number 31 while a date such as 2001-12-14 stays a string. If a value must stay text, put it in quotes in the YAML.

Why does the converter say my YAML is invalid?

Common causes are tabs used for indentation, a missing space after a colon, an unclosed bracket, or several documents separated by three dashes. Fix the indentation and quotes, then try again.

Can I convert a JSON file with a very large number?

The converter reads JSON the way a browser does. Whole numbers that are too large to be held exactly may be rounded in the output. Put such identifiers in quotes in the JSON so they stay exact.

Does YAML to JSON keep the order of keys?

Yes. Keys are written in the order they appear in the YAML text, and the JSON output is indented by two spaces. The tool does not sort keys in either direction.

Hvordan bruker du JSON- og YAML-konverterer?

Velg retning, lim inn en konfigurasjon og få resultatet klart til kopiering eller nedlasting.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.