ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / 
  • Importing YAML files
  • Assignment and reading
  • Managing references
  • Properties specific to YAML variables
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
YAML (Type of variable)
In french: YAML
The 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.
Example
V is YAML
Syntax

Declaring and assigning a YAML type Hide the details

<Variable name> is YAML = <Value>

OR
 <Variable name> is YAML
 <Variable name> = <Value>
<Variable name>:
Name of the variable to declare.
<Value>:
Value that will be assigned to the variable. A YAML variable can be assigned with:
  • NULL,
  • 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.
Remarks

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:
  1. 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.
  2. The JSON document appears in the "External descriptions" folder of the "Project explorer" pane. You have the ability to see its structure.
  3. Declare the variable as follows:
    <Variable name> is YAML, description =  <Document name>

    or
    <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.
  4. 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".
Managing comments
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.

Managing references

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 YAML variables

The following properties can be used to handle YAML variables:
Property nameType usedEffect
AliasCharacter stringAlias name to use if the element is referenced several times in the same document.
This property is read-only.
CommentAfterCharacter stringComment after the YAML element in the generated YAML string.
CommentBeforeCharacter stringComment before the YAML element in the generated YAML string.
CommentInternalCharacter stringInternal comment of the YAML element in the generated YAML string.
ExistBooleanIn read mode:
  • True if the element exists,
  • False otherwise.
In write mode:
  • True to validate the element,
  • False to delete the element.
YAMLFormatCharacter stringYAML string corresponding to the value of the element. If this string is not in YAML format, a warning is displayed.
MemberArray of YAML variablesMembers of the YAML variable.
NameCharacter stringMember name. Corresponds to empty string ("") if there is no member.
CountIntegerNumber of elements:
  • 1 for simple elements and objects,
  • Number of elements for arrays.
This property is read-only.
TypeIntegerType of element. This property is read-only.
ValueAll typesElement value.
Related Examples:
Handle YAML Unit examples (WINDEV): Handle YAML
[ + ] Handle YAML with the YAML WLanguage type
Minimum version required
  • Version 25
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 02/23/2024

Send a report | Local help