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

Convert YAML Settings to JSON for Node.js and Browser Code

Turn a YAML config file into valid JSON that JavaScript can load directly, and avoid indentation and type pitfalls.

YAML is pleasant to write by hand, with no braces or quotes in most places. JavaScript, however, loads JSON natively, and a browser cannot read YAML without a library. The YAML to JSON Converter turns your settings into JSON you can drop straight into code.

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

Why convert

JSON.parse and the built-in import of JSON files work everywhere without extra dependencies. YAML needs a parser library, which adds weight to a front-end bundle and one more thing to keep updated. For static configuration that rarely changes, converting once is simpler than parsing at runtime.

If you edit settings often, keep YAML as the source and convert whenever it changes.

Convert a file

  1. Copy the YAML content.
  2. Paste it into the YAML to JSON Converter.
  3. Read the formatted JSON on the output side.
  4. Check that lists and nested objects match what you intended.
  5. Copy it into a .json file and load it with import or JSON.parse in your app.
  6. Run the app and confirm the values arrive as expected.

Watch the types

YAML guesses types, and sometimes it guesses differently than you expect. In YAML 1.1, the unquoted values yes, no, on, and off can be read as booleans, and a version number like 1.10 can become the number 1.1. Quote anything that must stay a string. In the JSON output, check that strings have quotes and numbers do not.

Dates are another source of surprises, since some parsers turn them into date values, while JSON has no date type and writes them as text.

Indentation errors

  • Tabs are not allowed for indentation in YAML. Use spaces.
  • A single misaligned line changes which key it belongs to.
  • A colon followed by text without a space is part of the string, not a key.
  • Special characters such as colons or hash signs inside values need quotes.
  • A list item needs a dash followed by a space.

Things JSON cannot hold

YAML supports comments, anchors, and aliases for reuse. JSON has no comments, so they disappear in conversion, and a full YAML parser expands anchors into repeated copies. This converter handles basic YAML only, so run files that use anchors through a complete YAML library instead. If your comments explain settings, keep the YAML as the documented original and treat the JSON as a generated file. Add a note at the top of the YAML saying so.

Validate the result

After converting, run the output through a JSON validator and then load it in a tiny test script that prints a few expected values. If a number you expect is a string, or a list is a single value, trace it back to the YAML line. Fixing the source is better than fixing the JSON, so the next conversion stays correct.

Using the result in code

In Node.js you can read the file with the file system module and parse it, or import it directly in modern setups that support JSON imports. In the browser, fetch the file and call response.json(). Either way, keep secrets out of the file: anything shipped to a browser is visible to the user.

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

Comments (0)

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