ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / 
  • Importing files in JSON format
  • Reading and assigning a value to a JSON variable
  • Properties specific to JSON variables
  • Looping through the elements of a JSON variable
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
The JSON simplifies actions on data in JSON format.
Example
V is JSON
jedi is JSON = [
	{
	"id": 5,
	"name": "Luke Skywalker",
	"pilotingScore": 98,
	"shootingScore": 56,
	"isForceUser": true
	}
]
Syntax

Declaring and assigning a value to a JSON type Hide the details

<Variable name> is JSON = <Value>

OR
 <Variable name> is JSON
 <Variable name> = <Value>
<Variable name>:
Name of the variable to declare.
<Value>:
Value to be assigned to the variable. The following values can be assigned to a JSON variable:
  • 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 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:
  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. You have the ability to see its structure.
  3. Declare the variable as follows:
    <Variable name> is JSON, description =  <Document name>

    or
    <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.
  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 JSON by using the following syntax:
v2 is JSON, description="JSONFile.Member.SubMember"

v2 is JSON, <description="JSONFile.Member.SubMember">

Reading and assigning a value to a JSON variable

  • Assigning a value to 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 JSON variables

The following properties can be used to manipulate JSON variables:
Property nameType usedEffect
CountIntegerNumber of elements:
  • 0 for simple elements,
  • 1 for objects,
  • Number of elements for arrays.
This property is read-only.
ExistBoolean
  • True if the element exists,
  • False otherwise.
This property is read-only.
JSONFormatCharacter stringJSON string corresponding to the value of the element. If this string is not in JSON format, a warning is displayed.
MemberArray of JSON variablesMembers of the JSON variable.
Name Character stringMember name. Corresponds to empty string ("") if there is no member.
TypeIntegerType of element.
This property is read-only.
ValueAll types
  • Value of a simple element,
  • NULL for a complex element.

Looping through the elements of a JSON variable

To loop through the elements of a JSON variable, simply use a FOR loop.
JS is JSON
FOR i = 1 TO JS..Member..Count
	Trace(JS..Member[i]..Name)
END
  • Example: Copying a JSON variable to another JSON variable by looping through an array:
    JsonApplication1 is JSON <description="ListElementsControls1">
    JsonApplication2 is JSON <description="ListElementsControls2">

    FOR EACH JsonElement1 OF JsonApplication1.ArrElement
    JSonElement2 is JSON <description="ListElementsControls1.ArrElement">
    JsonElement2.Name = JsonElement1.Name

    FOR EACH JsonControl1 OF JsonElement1.ArrControl
    JsonControl2 is JSON <description="ListElementsControls1.ArrElement.ArrControl">
    JsonControl2.ChangeAllowed = JsonElement1.ChangeAllowed
    JsonControl2.Caption = JsonElement1.Caption
    JsonControl2.Name = JsonElement1.Name
    JsonControl2.Parent = JsonElement1.Parent
    JsonControl2.Type = JsonElement1.Type
    Add(JsonElement2.ArrControl, JsonControl2)
    END

    Add(JsonApplication2.ArrElement, JsonElement2)
    END
Minimum version required
  • Version 24
This page is also available for…
Comments
Navegar nos dados de um json
js is JSON
FOR i = 1 _TO_ js..Member..Count
js..Member[i]..Name
END
Boller
23 Oct. 2023

Last update: 03/28/2024

Send a report | Local help