Working with REST/JSON Process
Process Purpose
The "REST/JSON" process is used to parse data from a JSON response using an HTTP service.
You can parse up to 50 "path names" in one single process.
When you add a process, you are required to define its settings. This occurs in the process's properties window which is displayed automatically after having added the "REST/JSON" process. In this case, the properties window includes three tabs - "General", "Option" and "Error".
If any subsequent edition is required, double-click the process to open its properties window and enter the necessary modifications.
"General" tab
Fill in the following options:
HTTP Request |
|
URL |
Enter the URL OR click to access the URL Assistant. See Detail of URL Assistant. As an alternative, you can use a variable to define the URL (use the "Variable Select" option that is accessed if you right-click this box). |
Parse single response element to Variable |
|
JSON 'Path Name' column |
Select the JSON response's field(s) from the drop-down OR click and select a variable with that value. See Variable Usage. You can parse up to 50 "path names" in each "REST/JSON" process. |
Store into Variable column |
Click to select the variable that receives the data from the JSON response's field(s). See To Select/Create a Variable. |
Use the editing icons to the right of the table to move the rows up and down and to delete or add more rows.
Proceed to the "Option" tab.
"Options" tab
Fill in the following options:
Store full response (unparsed) to Variable |
|
Variable |
Click to select the variable that receives the unparsed data. See To Select/Create a Variable. |
Parse list of elements (array) to Data File |
|
Local File Name |
Select the data file that receives the parsed data from the drop-down. If necessary, click to edit the selected data file. See Editing a Data File. |
Select root element of array |
Select the JSON response's root element from the drop-down OR click and select a variable with that value. See Variable Usage. |
Field column |
Select the data file's field that receives the data from the drop-down. |
JSON 'Sub Path Name' or value column |
Select the JSON response's field(s) from the drop-down OR click and select a variable with that value. |
Use the editing icons to the right of the table to move the rows up and down and to delete or add more rows.
Click the "Error" tab to continue.
"Error" tab
Fill in the following options:
Store HTTP header response to Variable |
|
Full Header |
Click to select the variable that receives the full header from the REST/JSON Web Service. See To Select/Create a Variable. |
Status Code |
Click to select the variable that receives the status code from the REST/JSON Web Service. See To Select/Create a Variable. |
If … Go to |
|
Comm. Error |
Select a target location from the drop-down or list, in case there is a communications error. See Detail of a window below.
When defining a screen as a target destination (ex: via a “Go to” process), you CANNOT use variables to specify the name of that target screen. You must select the intended screen from the available drop-down/list. |
HTTP Error |
Select a target location from the drop-down or list, in case there is an "HTTP Error". See Detail of a window below.
When defining a screen as a target destination (ex: via a “Go to” process), you CANNOT use variables to specify the name of that target screen. You must select the intended screen from the available drop-down/list. |
JSON Error |
Select a target location from the drop-down or list, in case there is a "JSON Error". See Detail of a window below.
When defining a screen as a target destination (ex: via a “Go to” process), you CANNOT use variables to specify the name of that target screen. You must select the intended screen from the available drop-down/list. |
Detail of a window:
"S:Menu" is a screen included in the same program as the process.
"R:Routine_1" is a routine included in the same program as the process.
If required, use the icons on the upper right corner of the properties window:
Click it to define a JSON Data Source. It opens an "Select JSON Data Source" window. For more information on how to fill the options available, see Detail of a "Select JSON Data Source" window below.
Click this icon (located on the upper right corner of the properties window) to set up a time out. See Time Out.
Click it to create a new data file. Go to Creating a Data File to see how to fill in the several options available.
Use the icon to attach any relevant notes to this process. Click it and enter your notes in the resulting text box. These notes will be displayed in the corresponding "Actions" tab or "Process" window (in the "Notes" field) and in the "Developer Report".
After filling in the required options, click to conclude, or to abort the operation.
The added process is displayed in the corresponding "Actions" tab or "Process" window.
Detail of a "Select JSON Data Source" window
After clicking , you open the "Select JSON Data Source" window.
Fill in the following options
JSON Data Source |
|
JSON Data Source |
Select among the source file options (URL or File): Load from URL - Enter the required URL and click to verify/refresh the link. Load from File - Enter the path+file name OR click . |
JSON Content |
|
Provides a view of the data contained in the previously selected JSON web service. |
|
JSON Structure |
|
Provides a view of the previously selected JSON web service structure. |
|
Once you have selected the JSON source file, click to conclude or to abort the operation.
You can use relative paths to refer the file(s) you want to use in your project. See Working with Aliases.
If you want to use a label as a target destination, you can use the "Auto-Label" mechanism. This alternative to the "Set Label" process allows you to create a label in the properties window of a process - specifically, in the fields used to define target destinations (ex: the "If Error..." type fields). See To Automatically Create a Label.
Use the right-click in MCL-Designer's input boxes to access some related options as well as the general "Cut", "Copy"; "Paste"; "Search" actions (active/inactive according to the current context).
Ex: If you right-click the "Variable" input box (included in a "Conversion's" properties window), you are provided with general editing/search actions and other more specific options such as "Variable Select" (see "Variable Select"); "Variable Insert" (see "Variable Insert"); "Insert Special Character" (see To Insert Special Characters into a Control's Text Input Field) and "Localization Select" (see Localization List).
If you right-click another input box, it may provide other possibilities.