Creating Types From JSON Schema
- 22 Nov 2022
- 2 Minutes to read
- Print
- DarkLight
Creating Types From JSON Schema
- Updated on 22 Nov 2022
- 2 Minutes to read
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
Users may create a data structure from JSON Schema with the Create Types from JSON Schema option.
When retrieving data from a JSON object, the JSON Schema automatically defines and generates a Simple Flow Structure with data fields formatted in the schema.
When creating a JSON Schema, it is recommended to have the title property for all class definitions to provide consistency for naming the general structure. For example "title" : "Person"
Example
- In a Designer Project, select CREATE DATATYPES/INTEGRATION from the top action bar.
- In the Create DataTypes/Integration window, select XML/JSON/CSV from the right column then select Create Types from JSON Schema.
- In the Create Types from JSON Schema creation window, name the JSON Schema. It is also recommended to edit the default Namespace if the data structure resides in a deeply nested and/or populated environment.
- Set the Use Json Schema File to True to upload a JSON Schema file or False to paste the JSON code. This example uses the following JSON code:
{ "$id": "https://example.com/person.schema.json", "$schema": "http://json-schema.org/draft-07/schema#", "title": "Person", "type": "object", "properties": { "firstname": { "type": "string", "description": "The person's first name" }, "lastname" : { "type": "string", "description": "The person's last name" }, "age" : { "type": "integer", "minimum": 0, "description": "Age in years which must be equal to or greater than zero." } } }
When set to True, the Generate Complex Objects in Distinct Namespace generates Objects with the same name in different namespaces i.e., the text in brackets in the Data Structure's Folder View. Enabling this assists with organizing child Objects of the main parent Object. - Click CREATE. A JSON Schema Data Structure and a Simple Flow Structure will appear in the Designer Project.
- Right-click the Simple Flow Structure and select Edit Defined Data Structure to see that Structure is populated with the fields specified in the schema.
Making Changes to the JSON Data Structure
To make changes to the JSON Data Structure, users should only edit the JSON directly to ensure data remains consistent.
- Right-click the desired JsonSchemaDataStrucute and select Edit.
- When the Edit Json Schema window appears, make any necessary changes to the Json code. After all of the updates are completed, click SAVE SCHEMA.
Deserializing the JSON Schema
To test the JSON Schema, use a JSON Deserialize step to deserialize the object and view the data in the input/outputs in the Flow Debugger.
- In a Designer Folder, create a Flow.
- In the Toolbar, navigate to DATA > JSON and add a JSON Deserialize step to the Start step. Connect the outcome paths to the End step.
- On the Properties panel, check the IsOutputArray option under PARAMETERS. Set JSON Type to the JSON Schema "JSONSchemaPerson" from the dropdown menu.
- For the String to Deserialize input, set the mapping type to Merge Plain Text and click SHOW EDITOR.
- In the Merge Text Editor window, paste the following JSON code to represent an array of JSON Objects. Click SAVE.
[ { "firstname": "Guy", "lastname": "Person", "age": "32" }, { "firstname": "Hugh", "lastname": "Mann", "age": "30" } ]
Debug
- Click Debug from the top action bar.
- Select START DEBUGGING.
- In the Debugger, click the step, click Execution 1, and select View Input/Output Data to see that the JSON Schema was deserialized.
For further information on Data Structures, visit the Decisions Forum.
Was this article helpful?