Creating Types From JSON Schema
  • 16 Aug 2024
  • 2 Minutes to read
  • Dark
    Light

Creating Types From JSON Schema

  • Dark
    Light

Article summary

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

  1. In a Designer Project, select CREATE DATATYPES/INTEGRATION from the top action bar. 
  2. In the Create DataTypes/Integration window, select XML/JSON/CSV from the right column then select Create Types from JSON Schema.
  3. 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.
  4. 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.
  5. Click CREATE. A JSON Schema Data Structure and a Simple Flow Structure will appear in the Designer Project.
  6. 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.

  1. Right-click the desired JsonSchemaDataStrucute and select Edit.
  2. 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.

  1. In a Designer Folder, create a Flow.
  2. 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.
  3. On the Properties panel, check the IsOutputArray option under PARAMETERS. Set JSON Type to the JSON Schema "JSONSchemaPerson" from the dropdown menu.
  4. For the String to Deserialize input, set the mapping type to Merge Plain Text and click SHOW EDITOR.
  5. 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

  1. Click Debug from the top action bar. 
  2. Select START DEBUGGING.
  3. 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?