DevToolBoxFREE
BlogAdvertise

YAML 문법 & 검증: 일반적인 오류와 해결 방법

9분 읽기by DevToolBox

YAML은 Docker, Kubernetes, CI/CD 파이프라인 등 수많은 도구의 설정 포맷입니다. 사람에게 친화적인 문법이지만 놀라울 정도로 실수하기 쉽습니다.

YAML 사용처

  • Docker Compose
  • Kubernetes 매니페스트
  • GitHub Actions / GitLab CI
  • Ansible 플레이북
  • 설정 파일

기본 문법 규칙

들여쓰기

YAML은 공백(탭 불가)으로 들여쓰기합니다:

# ✅ Correct (2-space indentation)
server:
  host: localhost
  port: 8080
  database:
    name: myapp
    pool: 10

# ❌ Wrong (tab characters or inconsistent spaces)
server:
	host: localhost    # Tab character - INVALID!
   port: 8080        # 3 spaces - inconsistent!

키-값 쌍

콜론과 공백으로 구분합니다:

# ✅ Correct
name: John Doe
port: 8080

# ❌ Wrong - missing space after colon
name:John Doe

여러 줄 문자열

YAML은 두 가지 블록 스칼라 스타일을 제공합니다:

# | (literal block) - preserves newlines
description: |
  This is line one.
  This is line two.
  Each newline is preserved.

# > (folded block) - folds newlines to spaces
description: >
  This is a long paragraph
  that will be joined into
  a single line.

데이터 타입

타입문법예시
Stringplain, "quoted", 'quoted'name: John
Integer42, 0xFF, 0o77port: 8080
Float3.14, .inf, .nanpi: 3.14159
Booleantrue/falsedebug: true
Nullnull, ~, (empty)value: null
DateYYYY-MM-DDdate: 2026-02-10

"노르웨이 문제"

YAML 1.1에서 `NO`는 boolean `false`로 해석됩니다. 따옴표를 사용하세요:

# ❌ YAML 1.1 interprets these as booleans!
country: NO        # → false
answer: yes        # → true
switch: on         # → true

# ✅ Fix: quote the values
country: "NO"      # → string "NO"
answer: "yes"      # → string "yes"
switch: "on"       # → string "on"

컬렉션

# List (sequence)
fruits:
  - apple
  - banana
  - cherry

# Nested map
database:
  host: localhost
  port: 5432
  credentials:
    user: admin
    password: secret

# Inline / Flow style
fruits: [apple, banana, cherry]
point: {x: 10, y: 20}

흔한 10가지 YAML 오류

#오류원인해결
1탭 문자 오류탭으로 들여쓰기공백으로 교체
2일관성 없는 들여쓰기2칸과 4칸 혼용일관된 들여쓰기 사용
3콜론 뒤 공백 누락`key:value`로 작성콜론 뒤에 공백 추가
4따옴표 없는 특수문자:나 #을 포함한 값에 따옴표 없음특수문자 포함 문자열에 따옴표
5불리언 강제 변환yes/no가 불리언으로따옴표로 감싸기
6콜론 포함 문자열URL의 두 번째 콜론에서 끊김전체 값을 따옴표로
7중복 키같은 키가 두 번 등장중복 키 제거
8후행 공백값 뒤의 보이지 않는 공백편집기에서 후행 공백 제거
9리스트 들여쓰기 오류리스트 항목이 부모 키와 정렬 안 됨들여쓰기 수준 맞추기
10문서 구분자 누락여러 문서에 `---` 없음`---` 추가

YAML vs JSON vs TOML

기능YAMLJSONTOML
Comments# supportNone# support
Multi-line strings| and >\\n only""" triple quotes
Data typesRich (dates, etc.)Basic (6 types)Rich (dates, etc.)
ReadabilityHighMediumHigh
Machine parsingComplexSimpleMedium
Best forConfig filesAPIs, data exchangeApp config

모범 사례

  • CI/CD에서 YAML 린터 사용
  • 편집기에서 공백 문자 표시
  • 2칸 들여쓰기 사용
  • 오해될 수 있는 문자열에 따옴표
  • 스키마 검증 사용
  • 파일을 작고 모듈화

FAQ

YAML에서 탭을 사용할 수 있나요?

아니요. YAML은 들여쓰기에 탭 문자를 엄격히 금지합니다.

작은따옴표와 큰따옴표의 차이는?

작은따옴표는 리터럴 문자열, 큰따옴표는 이스케이프 시퀀스를 허용합니다.

YAML에서 null을 표현하려면?

`null`, `~`, 또는 빈 값을 사용합니다.

왜 YAML은 "NO"를 false로 처리하나요?

YAML 1.1 사양이 yes/no 등을 불리언으로 처리하기 때문입니다. YAML 1.2에서는 true/false만 인식합니다.

도움이 되었나요?

Stay Updated

Get weekly dev tips and new tool announcements.

No spam. Unsubscribe anytime.

Partner Picks

Sponsor this article

Place your product next to this developer topic with tracked clicks.

Ask about article sponsorship

This site uses cookies for analytics and to display ads. By continuing to browse, you agree. Privacy Policy