Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cdsousa/9c98897595177ed322b24643af4b68ce to your computer and use it in GitHub Desktop.
Save cdsousa/9c98897595177ed322b24643af4b68ce to your computer and use it in GitHub Desktop.
TOML vs YAML

Here's the canonical TOML example from the TOML README, and a YAML version of the same. Which looks nicer?

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

  [servers.beta]
  ip = "10.0.0.2"
  dc = "eqdc10"

[clients]
data = [ ["gamma", "delta"], [1, 2] ]

hosts = [
  "alpha",
  "omega"
]
title: YAML Example

owner:
  name: Tom Preston-Werner
  dob: 1979-05-27T07:32:00-08:00

database:
  server: 192.168.1.1
  ports: [ 8001, 8001, 8002 ]
  connection_max: 5000
  enabled: true

servers:

  alpha:
    ip: 10.0.0.1
    dc: eqdc10

  beta:
    ip: 10.0.0.2
    dc: eqdc10

clients:
  data: [ [gamma, delta], [1, 2] ]

  hosts:
    - alpha
    - omega
@ExternalReality
Copy link

Removing levels of nesting in favor of square brackets is a win for clarity.

@tyliggity
Copy link

How would YAML distinguish between a number and a string? TOML seems to do this easily but would a YAML parser automatically give you numbers since all strings and numbers look the same (no double quotes)?

@sexnine
Copy link

sexnine commented Nov 22, 2022

@tyliggity

How would YAML distinguish between a number and a string? TOML seems to do this easily but would a YAML parser automatically give you numbers since all strings and numbers look the same (no double quotes)?

I know this is an old ass question, but I'll leave this here for whoever else stumbles upon this.
In YAML, you can use quotes for strings if you'd like and I usually do all the time as I prefer things to be a bit more explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment