Getting Started with YAML

 

YAML language tutorial

http://www.ruanyifeng.com/blog/2016/07/yaml.html?f=tt

 

YAML to JSON conversion

http://nodeca.github.io/js-yaml/

 

 

The basic grammar rules are as follows.

  • Case Sensitive
  • Use indentation to indicate hierarchy
  • Tab key is not allowed when indenting, only spaces are allowed.
  • The number of spaces indented does not matter, as long as elements at the same level are left aligned

 

# Indicates a comment, which is ignored by the parser from this character until the end of the line.

There are three data structures supported by YAML.

  • Object: A collection of key-value pairs, also known as mapping/hashes/dictionary
  • Array: A set of values ​​in order, also known as a sequence/list
  • scalars: single, indivisible values

 

 

Example:

 

YAML format:

filebeat.prospectors:
- input_type: log
  document_type: iop-apigw-server
  fields:
    source_type: iop-apigw
  fields_under_root: true
  multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}'
  multiline.negate: true
  multiline.match: after
  paths:
   - E:/git/api-gateway-engine/log/apigw-server.log
  
output.kafka:
  enabled: true
  hosts:
   - 10.110.22.32:9092
   - 10.110.22.33:9092
   - 10.110.22.34:9092
  topic: iop-apigw

 

Convert to JSON

{
    "filebeat.prospectors": [
        {
            "input_type": "log",
            "document_type": "iop-apigw-server",
            "fields": {
                "source_type": "iop-apigw"
            },
            "fields_under_root": true,
            "multiline.pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}",
            "multiline.negate": true,
            "multiline.match": "after",
            "paths": [
                "E:/git/api-gateway-engine/log/apigw-server.log"
            ]
        }
    ],
    "output.kafka": {
        "enabled": true,
        "hosts": [
            "10.110.22.32:9092",
            "10.110.22.33:9092",
            "10.110.22.34:9092"
        ],
        "topic": "iop-apigw"
    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326123056&siteId=291194637