Skip to content
OddsockLocal
Local
Source text
{
  "color": "red",
  "count": 2
}
1 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste YAML or JSON.
  2. Set Conversion to to-json or from-json.
  3. Read the object, or the YAML text.
  4. A parser error is a syntax problem in the direction you chose.

What is YAML and JSON?

This page converts, and the direction is a control. Conversion defaults to to-json. color: red and count: 2 becomes a JSON object with color red and count 2. Switch to from-json and {"greet":"hello"} becomes greet: hello followed by a newline. Numbers stay numbers. The formatter page only reprints YAML and will not produce this object.

Read more

The YAML parser’s errors surface as the message, so a bad indent fails rather than becoming a JSON string of the raw text. Alias expansion is capped, same as the formatter. From-json parses JSON first, so a trailing comma or a bare key fails as JSON, not as YAML.

One document at a time. A YAML stream of several documents is not what to-json is aimed at. If you need the data loaded into SQL, the JSON to SQL page takes the array you get after you have shaped it.

Use cases

  • A config is YAML and a tool wants the JSON object with color and count.
  • A JSON snippet {"greet":"hello"} should become a YAML scalar you can drop into a config.
  • You want a parse failure on broken YAML rather than a string that pretends the conversion worked.
  • The formatter’s reprint is not enough, because the next step is JSON.

A mapping to JSON, and a JSON string back to YAML

to-json of color: red and count: 2. from-json of {"greet":"hello"}.

JSON: { "color": "red", "count": 2 }. YAML: greet: hello

Why use Oddsock

Direction is explicit. A page that guesses from the first character will misread a JSON string that happens to be valid YAML.

Related tools

Using this tool

With to-json, an object { "color": "red", "count": 2 } when count is the second key. The number 2 stays a number.