JSON conversion YAML

Just like YAML Ain't Markup Language represented by YAML, YAML is a concise non-markup language. YAML is data-centric, using whitespace, indentation, and branching to organize the data to make the presentation more concise and easy to read.

While learning the rules, you can practice on the YAML conversion JSON webpage of the online Demo

Basic rules
YAML has the following basic rules: 
1. Case sensitivity 
2. Use indentation to indicate hierarchical relationships 
3. Tab indentation is prohibited, only the space bar 
4. There is no limit to the length of indentation, as long as the elements are aligned, it means that these elements belong One level. 
5. Use # to indicate comments 
6. Strings can be marked without quotation marks

7 people understand that when encountering json braces, they will wrap and indent. When encountering parentheses, they will not only wrap and indent but also add-

Three data structures
1. Map, hash table 
uses colon (:) to represent key-value pairs, all key-value pairs with the same indentation belong to a map, example:

#YAML display
age: 12
name: huang

# The corresponding Json means
{'age':12,'name':'huang'
You can also write a map on one line:

# YAML display
{age: 12, name: huang}

# The corresponding Json representation
{'age':12,'name':'huang'}


2. List and array 
use hyphen (-) to indicate:

# YAML said
-a
-b
-12

# Corresponding to Json means
['a','b',12]

can also be written in one line:

# YAML means
[a,b,c]

# Corresponding to Json means
['a','b','c']

3. scalar, the
smallest unit of scalar  data, cannot be divided.


The elements of the nested map and list of the data structure can be another map or list or a scalar. There are four common types of data nesting: 
1. Map nesting map

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

# Corresponding to Json representation
{websites: 
   {YAML:'yaml.org',
     Ruby:'ruby-lang.org',
     Python:'python.org',
     Perl:'use.perl.org'}}

2. Map nesting list

# YAML表示
languages:
 - Ruby
 - Perl
 - Python 
 - c

# Corresponding to Json representation
{languages: ['Ruby','Perl','Python','c']}

3. List nested list

# YAML表示
-
  - Ruby
  - Perl
  - Python 

  - c
  - c++
  - java

# Corresponding to Json representation
[['Ruby','Perl','Python' ], ['c','c++','java']]

In addition to this, the structure can also be expressed as follows

# Method 2
--Ruby
  -Perl
  -Python 
--c
  -c++
  -java

# Method 3-
[Ruby,Perl,Python]
-[c,c++,java]

4. List nested map

# YAML表示
-
  id: 1
  name: huang
-
  id: 2
  name: liao

# Corresponding to Json representation
[{id: 1, name:'huang' }, {id: 2, name:'liao'}]
--------------------- 
Original: https://blog.csdn.net/vincent_hbl/article/details/75411243 
Copyright statement: This article is the original article of the blogger, please attach the link to the blog post if you reprint it!

Guess you like

Origin blog.csdn.net/yu1336199790/article/details/89215474