- Importing files in JSON format
- Assignment and reading
- Properties specific to the description of JSON variables
JSON (Type of variable)
In french: JSON
type makes it possible to simplify actions on data in JSON format.
jedi is JSON = [
"name": "Luke Skywalker",
Declaring and assigning a JSON type Hide the details
<Variable name> is JSON = <Value>
<Variable name> is JSON
<Variable name> = <Value>
Name of the variable to declare.
Value that will be assigned to the variable. A JSON 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 files in JSON format
JSON 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 JSON 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. You have the ability to see its structure.
- Declare the variable as follows:
<Variable name> is JSON, description = <Document name>
<Variable name> is JSON <description = "Document name">
can correspond to the name of the sample document (with or without extension).
Remark: This declaration can be made automatically by dragging and dropping the name of the text document directly from the project explorer.
- 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 JSON by using the following syntax:
v2 is JSON, description="JSONFile.Member.SubMember"
v2 is JSON, <description="JSONFile.Member.SubMember">
Assignment and reading
- Assigning a JSON variable
The syntax "j = ..." tries to analyze the value as a JSON string. This syntax is "almost" equivalent to "j..JSONFormat = ..." except if the JSON string is invalid: it is then copied directly without being interpreted, as the value of the JSON element.
The "j..Member = ..." syntax assigns the value of the member. This syntax is equivalent to "j..Member..Value =... ".
- Reading a JSON variable
The "... = j" syntax returns the JSON string that corresponds to the content of the variable. This syntax is equivalent to "... =j..JSONFormat ".
The syntax "... = j..Member" returns the value of the member. This syntax is equivalent to "... =j..Member..Value".
Properties specific to the description of JSON variables
The following properties can be used to handle a JSON variable:
|Property name||Type used||Effect|
|Count||Integer||Number of elements: |
This property is read-only.
- 0 for simple elements,
- 1 for objects,
- Number of elements for arrays.
This property is read-only.
- True if the element exists,
- False otherwise.
|JSONFormat||Character string||JSON string corresponding to the value of the element. If this string is not in JSON format, a warning is displayed. |
|Member||Array of JSON variables||Members of the JSON variable. |
|Name ||Character string||Member name. Corresponds to empty string ("") if there is no member. |
|Type||Integer||Type of element.
This property is read-only.|
- Value of a simple element,
- NULL for a complex element.
This page is also available for…