- Importing YAML files
- Assignment and reading
- Managing references
- Properties specific to the description of YAML variables
YAML (Type of variable)
In french: YAML
type simplifies the handling of data in YAML format.
YAML is a data serialization format that allows for good human-readability while maintaining a high level of accuracy. It is similar to JSON and offers some interesting additional features (it is also possible to include JSON in YAML).
These characteristics make it very useful for:
- data exchanges between computer systems,
- configuration files.
These are the specific features of YAML:
- comments (especially useful for configuration files),
- tags, data type information (useful in the context of serialization/deserialization round trips),
- aliases within the document to avoid repetitions.
Declaring and assigning a YAML type Hide the details
<Variable name> is YAML = <Value>
<Variable name> is YAML
<Variable name> = <Value>
Name of the variable to declare.
Value that will be assigned to the variable. A YAML variable can be assigned with:
- a Boolean (True or False),
- a numeric,
- a date (automatically converted into string in RFC format),
- an Ansi or Unicode string that contains data,
- an Ansi string that contains data in JSON format.
Importing YAML files
YAML variables can be declared by specifying a sample document (a text file). The structure of this document will be read by WINDEV, WEBDEV and WINDEV Mobile. Therefore, the automatic completion will be available for the names of nodes in the code editor.
To declare a YAML variable with a sample document:
- Add the text document to the project using one of the following methods:
- on the "Project" tab, in the "Project" group, expand " List of elements" and click "List of project elements". The list of project elements is displayed. Click on "Add" and select the text document.
- drag the file and drop it in the "External descriptions" folder of the "Project explorer" pane.
- in the "Project explorer" pane, select the "External descriptions" folder, then "Import an XML or JSON into this project" in the context menu.
- The JSON document appears in the "External descriptions" folder of the "Project explorer" pane. You have the ability to see its structure.
- Declare the variable as follows:
<Variable name> is YAML, description = <Document name>
<Variable name> is YAML <description = "Document name">
<Document name> can correspond to the name of the sample document (with or without extension).
Remark: This declaration can be obtained automatically by "dropping" the name of the text document directly from the "Project Explorer" pane.
- You can directly access the variable nodes by their names. These names are automatically proposed by the automatic completion mechanism of the code editor.
Remark: It is also possible to obtain compilation assistance and verification on a sub-part of the YAML by using the following syntax:
v2 is YAML, description="JSONFile.Member.SubMember"
v2 is YAML, <description="JSONFile.Member.SubMember">
Assignment and reading
Assigning a YAML variable
The "j = ..." syntax tries to analyze the value as a YAML string. This syntax is "almost" equivalent to "j.YAMLFormat = ..." except if the YAML string is invalid: it is then copied directly without being interpreted, as the value of the YAML element.
The "j.Member = ..." syntax assigns the value of the member. This syntax is equivalent to "j.Member.Value =... ".
Reading a YAML variable
The "... = j" syntax returns the YAML string that corresponds to the content of the variable. This syntax is equivalent to "... =j.YAMLFormat ".
The "... = j.Member" syntax returns the value of the member. This syntax is equivalent to "... =j.Member.Value".
Each comment line is analyzed :
- if the line contains a '#' character, this character will be ignored, as well as all the characters before it. The rest will be considered as a comment (will appear in the YAML string preceded by a '#' character).
- if it is empty, an empty line will be integrated into the YAML string.
Remark: Imported and generated YAML
Most comments and the general format of the YAML document are imported and used in the following export, in order to generate a YAML document that is very similar to the original.
The original indentation is not preserved, it is regenerated.
To reference a member of an existing YAML from another member of the object, use the '<-' operator.
Config is YAML
Config.Default.HTTPConfig.Port = 80
Config.Default.HTTPConfig.Protocol = HTTP
Config.Server.Internal.Configuration <- Config.Default.HTTPConfig
Config.Server.InternalBackup.Configuration <- Config.Default.HTTPConfig
Config.Server.External.Configuration.Port = 443
Config.Server.External.Configuration.Protocol = HTTPS
Properties specific to the description of YAML variables
The following properties can be used to handle a YAML variable:
|Property name||Type used||Effect|
|Alias||Character string||Alias name to use if the element is referenced several times in the same document. |
This property is read-only.
|CommentAfter||Character string||Comment after the YAML element in the generated YAML string. |
|CommentBefore||Character string||Comment before the YAML element in the generated YAML string. |
|CommentInternal||Character string||Internal comment of the YAML element in the generated YAML string. |
|Exist||Boolean||In read mode: |
In write mode:
- True if the element exists,
- False otherwise.
- True to validate the element,
- False to delete the element.
|YAMLFormat||Character string||YAML string corresponding to the value of the element. If this string is not in YAML format, a warning is displayed. |
|Member||Array of YAML variables||Members of the YAML variable. |
|Name||Character string||Member name. Corresponds to empty string ("") if there is no member.|
|Count||Integer||Number of elements: |
This property is read-only.
- 1 for simple elements and objects,
- Number of elements for arrays.
|Type||Integer||Type of element.
This property is read-only.|
|Value||All types||Element value. |
Unit examples (WINDEV): Handle YAML
This page is also available for…
Click [Add] to post a comment