知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

    • Java basic

    • Java OOP

    • 应知

    • 扩展

      • Theory:Units of information
      • Theory:IDE
      • Theory:IDEA
      • Theory:Build tools
      • Theory:Operating systems
      • Theory:Gradle basics
      • Theory:Basic project with Gradle
      • Theory:Building apps using Gradle
      • Theory:Dependency management
      • Theory:Formatted output
      • Theory:Libraries
      • Theory:Frameworks
      • Theory:Modules
      • Theory:Introduction to software architecture
      • Theory:Class Diagrams
      • Theory:Text blocks
      • Theory:YAML
        • Introduction
        • Basic data types
        • Maps
        • Lists
        • Combination
        • Comments
        • Conclusion
      • Theory:XML
      • Theory:JSON
    • IO & Stream

    • Error & Exception

    • Algorithm & Data structure

    • Design pattern

    • Web

    • Spring boot

  • 练习题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • Hyperskill - Java
  • 扩展
Jim
2022-07-19
目录

Theory:YAML

# Introduction

Imagine objects with complex structures. For example, you have a large dictionary or a list with a bunch of other values. You need to preserve such an object without losing its structure. In other words, you want to serialize it. It's also good if the format of serialization has a simple syntax and is human-readable. So, let's get acquainted with a famous data format called YAML.

img

YAML is a recursive acronym for YAML Ain't Markup Language**.** It's a human-readable data serialization standard for all programming languages. It is commonly used for configuration files, and for storing and transferring data. It’s difficult to escape YAML if you’re doing anything related to software configuration. The usual extensions for YAML files are .yaml and .yml.

Let's take a closer look at this language in order to appreciate all its simplicity and functionality. We'll go over basic types, structures, and syntax.

# Basic data types

YAML supports all essential data types like numbers, strings, booleans, etc. It recognizes some language-specific data types, such as dates, timestamps, and special numerical values. So, the list of basic YAML data types includes:

  • integers like 15, 123
  • strings like "15", 'Hello, YAML!', which may be enclosed either in double or single quotation marks
  • floats like 15.033
  • booleans (true or false)
  • null type (null)

YAML auto-detects the type of data, but users can specify the type they need using !!. For example, if you need to specify the string yes, you need to write !!str yes.

Now you know the basic data types in YAML. Let's figure out the structures and their syntax.

# Maps

Mapping consists of key-value pairs. For example:

---
object: Book

metadata:  
  name: Three Men in a Boat
  author: Jerome K Jerome 
  genre: humorous account
  
published:
  year: 1889
  country: United Kingdom
1
2
3
4
5
6
7
8
9
10
11

The first line is a separator. It's optional unless you’re trying to define multiple structures in a single file. Then there is a set of key: value pairs as a block. Pairs are called scalars. The syntax is clean and simple; the usual format symbols, such as braces, square brackets, closing tags, or quotation marks, are unnecessary. Scalars are colon-separated, and there should be a space between the map elements. Note, that In YAML indentation is always done with spaces, not tabs.

# Lists

The lists in YAML are sequences of objects, as the example below shows.

animals:
  - cat
  - dog
  - bird
1
2
3
4

The number of items in the list is not limited. Each item on the list should start with a dash. Elements are separated from the parent with spaces; after a parent name there should be a colon. The example above represents a block style. In flow style, the list looks like this: [cat, dog, bird].

These are the structures. Next, we'll learn how to combine them.

# Combination

Maps and lists can be combined, so that one may have maps of maps, or maps of lists, or lists of lists, or lists of maps. Let's consider an example of a to-do map, where keys are weekends and values are lists of things to do during each day:

weekend:
  saturday: 
    - order cleaning
    - order a pizza
    - watch new series
  sunday: 
    - go to yoga 
    - hang out with a friend 
1
2
3
4
5
6
7
8

Also, if you need to denote a string that preserves newlines instead of a list, use | character:

saturday: |
  order cleaning
  order a pizza
  watch new series
1
2
3
4

Great, now you know how to use structures. The last important thing we should mention here is comments.

# Comments

One may add comments to the YAML file. Comments start with # and go till newline. They can be made anywhere in the line, for example:

# The comment
metadata:  # this is metadata
  name: Three Men in a Boat
  author: Jerome K Jerome
  genre: humorous account
1
2
3
4
5

# Conclusion

To sum up, we've discussed that

  • YAML is a human-readable text-based format that lets you easily specify configuration-type information
  • YAML supports integers, strings, floats, booleans, and null data types
  • there are two data structures in YAML, lists and maps, that can also be combined
  • comments can be added to YAML file

Let's get to the tasks!

编辑 (opens new window)
#Language
上次更新: 2022/09/26, 16:55:15
Theory:Text blocks
Theory:XML

← Theory:Text blocks Theory:XML→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式