course n°2 · Découverte

The Formats

MD for humans, YAML for config, JSON for the machine. Structure, never the content.

~11 min7 stations
▶ video🧩 exercises📄 cheat sheet

42 seconds · English captions included · 8.0 Mo

The 7 things you'll know how to do

Lesson 2: the Formats

Regarde la leçon (42 s) : trois formats, une seule règle — c'est du texte STRUCTURÉ pour quelqu'un.

Write for a human

Crée `readme` : une vraie chaîne Markdown avec un titre qui commence par « # » et du gras entre doubles astérisques.

Write for the config

Complète `config` (YAML) pour que `niveau` vaille l'ENTIER 1 — puis laisse le parseur vérifier : YAML.safe_load(config).

The slippery slope

Indentation ! Complète `config` avec un objet imbriqué : `base.host` doit valoir « localhost » (2 espaces sous `base:`).

Write for the machine

Complète `api` (JSON) : guillemets sur les clés, virgules partout, `niveau` = 1. JSON.parse(api) doit passer.

Same data, three costumes

Complète `donnee` en JSON pour que les trois formats disent la même chose : langue = ruby (le Markdown et le YAML sont déjà faits).

Lesson 2: OK

Sans aide : écris `payload` — un JSON avec une clé « tags » qui contient un tableau d'AU MOINS 2 chaînes — et parse-le.

Share the lesson

← all courses

📄 The cheat sheet

print it, stick it on your monitor, pretend it was your idea

📄 Cheat sheet — The Formats (MD · YAML · JSON)

Three formats, one rule: structured text for someone.

The choice, once and for all

You're writing for… You use Example
a human (README, doc) Markdown # Title · **bold**
a config (you, tomorrow) YAML langue: ruby
a machine (API, file) JSON {"langue": "ruby"}

Markdown — to be read

# Mon projet
Du **gras**, du *italique*, et une [liste](https://example.com)

Zero execution, zero dependency. Your README talks, that's it.

YAML — to be configured

langue: ruby
niveau: 1          # no quotes → YAML guesses INTEGER

base:
  host: localhost  # 2 spaces = nested. No tabs. Not 0.

Trap #1: "1" (quoted) stays a String. 1 is an Integer. Your niveau == 1 depends on it. Trap #2: the indentation is the structure. One bad indent = everything derails.

JSON — to be parsed

{
  "langue": "ruby",
  "niveau": 1
}

Keys quoted, commas between pairs (never after the last), balanced braces. Trap #1: the missing comma at 3 a.m. It's her. Always her.

The sentence that unlocks everything

You change the shape, never the content. The three say the same thing — only the reader changes.

The Ruby reflex

require "yaml"
YAML.safe_load(config)["langue"]   # => "ruby"  (and it raises if broken)

require "json"
JSON.parse(payload)["tags"]        # => ["ruby", "formats"]

A parser exists: never guess the structure, have it checked.


SlopCourse Microduck — from slop to clean code.