developer · Browser tool
Config Format Converter
Move a config file between YAML, JSON and TOML. The parser covers the subset config files actually use and stops with a message when it meets anything else.
Source
Converted
Comments never survive a conversion. None of the three formats can hold another format's comments in the right place, so they are dropped rather than parked somewhere misleading.
What this does and what it refuses
The file is parsed into a plain tree of maps, lists, strings, numbers, booleans and nulls, then written out again in the target format. Every parser and writer here is hand-written, so the honest thing is to tell you exactly where the edges are. When input falls outside the list below, the tool stops and says which line it choked on. It will not guess, because a config that has been quietly mangled is worse than one that failed to convert.
YAML, supported
Block mappings and sequences at any depth, plain and quoted scalars, flow collections such as [1, 2] and {a: 1}, comments, a single leading ---, literal (|) and folded (>) block scalars with - and + chomping, and the core scalar types: integers, floats, hexadecimal, true/false, null and ~. Following YAML 1.2, yes, no, on and off stay strings; quote them if you meant strings in a YAML 1.1 reader too.
YAML, refused
Anchors and aliases (&base, *base), merge keys (<<:), explicit tags (!!str), complex keys (? ), more than one document in a file, and plain scalars that run across several lines without a | or > marker. Tabs in indentation are rejected, which matches every real YAML parser.
TOML, supported
Tables, dotted keys, arrays of tables, inline tables, arrays including nested ones, basic and literal strings in both single-line and triple-quoted form, integers in decimal, hex, octal and binary with _ separators, floats, and booleans. Dates and times are read but kept as strings, because JavaScript's Date would throw away the offset information that makes a TOML datetime worth writing. inf and nan are refused since JSON cannot hold them.
Where conversions lose something
TOML has no null. A tree containing one cannot be written as TOML and the tool names the offending key instead of inventing an empty string for it. JavaScript has a single number type, so a YAML 1.0 and a YAML 1 arrive here identically and both come out as 1 — if a float matters to the program reading your file, check it afterwards. Integers beyond 2^53 are refused rather than silently rounded. TOML also needs a map at the top level, so a JSON array document cannot become TOML.