Configuration file of the Yaml language tutorial

Source: Internet
Author: User
Tags arrays data structures hash
transferred from: Http://www.ruanyifeng.com/blog/2016/07/yaml.html?f=tt YAML Language Tutorials

Author: Ruan Yi Feng

Date: July 4, 2016

Programming is unavoidable to write configuration files, how to write configuration is also a learning.

YAML is a language dedicated to writing configuration files, very concise and powerful, far more convenient than JSON format.

This article describes the syntax of YAML, taking the implementation of JS-YAML as an example. You can go to the online Demo to verify the example below.

First, Introduction

The goal of the YAML language (pronounced/ˈjæməl/) is to facilitate human literacy. It is essentially a general purpose data serialization format.

It has the following basic syntax rules. Case sensitive use indentation to indicate that a hierarchical relationship is indented without using the TAB key, only spaces are allowed. The number of spaces you indent is not important, as long as the same level elements are left aligned

# indicates a comment, which is ignored by the parser, from the word selector until the end of the line.

YAML supports three types of data structures. Object: A collection of key-value pairs, also known as a map (mapping)/hash (hashes)/dictionary (Dictionary) array: a set of sequential values, also known as sequences (sequence)/list (lists) of pure quantities (scalars): Single, non-re-divided values

These three data structures are described below. second, the object

A set of key-value pairs for an object, expressed using a colon structure.

Animal:pets

Switch to JavaScript as follows.

{animal: ' Pets '}

Yaml also allows another way to write all key-value pairs into an inline object.

Hash: {Name:steve, Foo:bar} 

Switch to JavaScript as follows.

{hash: {name: ' Steve ', foo: ' Bar '}}
three, array

A set of lines at the beginning of a conjunction line that forms an array.

-Cat
-Dog
-Goldfish

Switch to JavaScript as follows.

[' Cat ', ' Dog ', ' goldfish ']

A child member of a data structure is an array, and you can indent a space below the item.

-
 -Cat
 -Dog
 -Goldfish

Switch to JavaScript as follows.

[[' Cat ', ' Dog ', ' goldfish ']

Arrays can also be used in inline notation.

Animal: [Cat, Dog]

Switch to JavaScript as follows.

{animal: [' Cat ', ' Dog ']}
Four, composite structure

Objects and arrays can be used together to form a composite structure.

Languages:
 -Ruby
 -Perl
 -Python 
websites:
 YAML:yaml.org 
 ruby:ruby-lang.org 
 Python:python.org 
 Perl:use.perl.org 

Switch to JavaScript as follows.

{languages: [' Ruby ', ' Perl ', ' python '],
  websites: 
   {YAML: ' yaml.org ',
     Ruby: ' ruby-lang.org ',
     Python: ' python.org ',
     Perl: ' Use.perl.org '}}
Five, pure quantity

The pure quantity is the most basic, non-sub-divided value. The following data types belong to the pure amount of JavaScript.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.