YAML — Practical Examples
Types in YAML
YAML booleans, nulls, and numbers map naturally to JSON types:
printf 'active: true\ncount: 42\nlabel: null\n' | \
fimod s --input-format yaml -e 'data' --output-format json
Convert to other formats
# YAML → JSON
printf 'host: localhost\nport: 5432\ndb: myapp\n' | \
fimod s --input-format yaml -e 'data' --output-format json
# YAML → TOML
printf 'host: localhost\nport: 5432\ndb: myapp\n' | \
fimod s --input-format yaml -e 'data' --output-format toml
For a file:
cat > /tmp/config.yaml << 'EOF'
host: localhost
port: 5432
db: myapp
EOF
fimod s -i /tmp/config.yaml -e 'data' --output-format json
fimod s -i /tmp/config.yaml -e 'data' -o /tmp/config.toml
TOML requires a root-level object
Arrays or scalars at the root will fail to serialize as TOML — TOML spec constraint.
Normalize / reformat in-place
cat > /tmp/config.yaml << 'EOF'
host: localhost
port: 5432
db: myapp
EOF
fimod s -i /tmp/config.yaml -e 'data' --in-place
cat /tmp/config.yaml
Filter a list
printf 'users:\n - name: Alice\n role: admin\n - name: Bob\n role: user\n' | \
fimod s --input-format yaml \
-e '[u for u in data["users"] if u["role"] == "admin"]' \
--output-format yaml
Edit a nested value
cat > /tmp/config.yaml << 'EOF'
database:
host: localhost
port: 5432
EOF
fimod s -i /tmp/config.yaml -e 'dp_set(data, "database.port", 5433)' --output-format yaml