Yaml은 사람이 쉽게 읽을 수 있는 데이터 직렬화 양식으로, 주로 설정 파일과 데이터가 저장 또는 전송되는 응용 프로그램에 사용됩니다. 원래 YAML의 뜻은 "또 다른 마크업 언어 (Yet Another Markup Language)" 였으나, 오늘날 "YAML은 마크업 언어가 아니다 (YAML Ain't Markup Language)" 라는 뜻으로 더 많이 언급됩니다.
더 많은 정보는 YAML 공식 웹사이트를 참고하세요.
# 따옴표 없는 문자열
title : Guide to YAML
# 따옴표 있는 문자열
title : 'Guide to YAML'
# 여러 줄의 문자열
Demons : |
When the days are cold
And the cards all fold
And the saints we see
Are all made of gold
# 정수형
count: 7
# 실수형
price: 32.05
# 과학적 표기법
total: 4.5e+4
isDarkMode: false
isDarkMode: False
isDarkMode: FALSE
true:
y
,Y
,Yes
,YES
,true
,True
,TRUE
,on
,On
,ON
false:n
,N
,No
,NO
,false
,False
,FALSE
,off
,Off
,OFF
username:
username: ~
username: null
username: Null
username: NULL
date: 2021-05-24
canonical: 2021-05-24T02:59:43.1Z
valid iso8601: 2021-05-24t21:59:43.10-05:00
space separated: 2021-05-24 21:59:43.10 -5
# 하이픈
people:
- Elena
- James
- Olivia
# 인라인
people: [Elena, James, Olivia]
Black Widow:
director: Cate Shortland
release-date: 2021-07-09
cast: [Scarlett Johansson, David Harbour, Florence Pugh, O-T Fagbenle, and Rachel Weisz]
overview: |
In Marvel Studios’ action-packed spy thriller “Black Widow,” Natasha Romanoff aka Black Widow confronts the darker parts of her ledger when a dangerous conspiracy with ties to her past arises.
Pursued by a force that will stop at nothing to bring her down, Natasha must deal with her history as a spy and the broken relationships left in her wake long before she became an Avenger.
- Black Widow:
director: Cate Shortland
release-date: 2021-07-09
cast: [Scarlett Johansson, David Harbour, Florence Pugh, O-T Fagbenle, and Rachel Weisz]
overview: |
In Marvel Studios’ action-packed spy thriller “Black Widow,” Natasha Romanoff aka Black Widow confronts the darker parts of her ledger when a dangerous conspiracy with ties to her past arises.
Pursued by a force that will stop at nothing to bring her down, Natasha must deal with her history as a spy and the broken relationships left in her wake long before she became an Avenger.
- Shang-Chi:
director: Destin Daniel Cretton
release-date: 2021-09-03
cast: [Simu Liu, Awkwafina, Tony Leung, Michelle Yeoh, Fala Chen, Meng’er Zhang, Florian Munteanu and Ronny Chieng]
overview: |
Marvel Studios' "Shang-Chi and The Legend of The Ten Rings" stars Simu Liu as Shang-Chi, who must confront the past he thought he left behind when he is drawn into the web of the mysterious Ten Rings organization.
The film also stars Tony Leung as Wenwu, Awkwafina as Shang-Chi's friend Katy and Michelle Yeoh as Jiang Nan, as well as Fala Chen, Meng'er Zhang, Florian Munteanu and Ronny Chieng.
YAML은 주로 구조의 들여쓰기에 의존하기 때문에 구분자 충돌 발생이 적습니다. YAML은 따옴표나 중괄호에 민감하지 않기 때문에 XML, JSON 또는 YAML 문서를 블록에 들여쓰기만 하면 YAML 문서 안에 포함할 수 있습니다 (|
또는 >
사용).
message: |
<blockquote style="font: italic 1em serif">
<p>"Three is always greater than two,
even for large values of two"</p>
<p>--Author Unknown</p>
</blockquote>
# whole line comment
Item # inline comment
향후 참조용으로 노드를 표시하여 노드를 재사용할 수 있습니다. 노드를 표시하기 위해 &
문자를 사용하고 참조하기 위해 *
를 사용합니다.
people:
- first: &Elena
name: Elena
last-name: Kim
age: 25
- second: &James
name: James
last-name: Lee
age: 35
one: *Elena
two: *James
YAML은 엔터티의 데이터 형식을 자동으로 검색하지만, 값 앞에 !!
의 형식을 포함하여 데이터 형식을 명시적으로 캐스트할 수도 있습니다.
explicit-int: !!int 3.2 # an integer
explicit-str: !!str 30.25 # a string
explicit-bool: !!bool yes # a boolean
YamlDotNet은 닷넷 스탠다드와 기타 닷넷 런타임을 위한 YAML 라이브러리입니다.
YamlDotNet은 XmlDocument와 유사한 상위 수준의 객체 모델뿐만 아니라 YAML의 하위 수준의 구문 분석 기능을 제공합니다. 또한 개체를 읽고 쓸 수 있는 직렬화 라이브러리도 포함되어 있습니다.
콘솔창에 아래 명령어를 입력하여 패키지를 설치합니다.
PM> Install-Package YamlDotNet
또는 아래와 같이 Nuget Package Manager를 통해 YamlDotNet 패키지를 설치할 수도 있습니다.
using YamlDotNet.Serialization
using YamlDotNet.Serialization.NamingConventions
var deserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
var result = deserializer.Deserialize<List<ArticleMenuModel>>(strContent);
string yaml;
List<Model> datas;
var mySerializer = new SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
yaml = mySerializer.Serialize(datas);
📑 CODE PROJECT YAML Parser in C#
📑 C# Corner The Basics Of YAML In 5 Minutes Or Less!
📑 DEV Community Introduction to YAML
📑 YamlDotNet GitHub
📑 WIKIPEDIA YAML