Creating a New Schema by Using JSON

Creating a new entity type by copying an existing entity type is a good way to go …. provided that you want the new entity type to have the exact same format as one of your existing entity types. But what if your new entity type needs to be different from all of your existing entity types? In that case, you might want to use JSON (JavaScript Object Notation) to create the schema for the new entity type, then use Registration Builder to either paste in or import that schema.

We won’t go over the ins and outs of creating a JSON representation of an entity type schema in this documentation; that’s something you’re highly unlikely to do in the Console anyway. Suffice to say that a very simple JSON schema (one that only includes two minimally-defined attributes: name and description) will look similar to this:

    "name": "name",
    "type": "string",
    "case-sensitive": false
}, {
    "name": "description",
    "type": "string",
    "length": 1000,
    "case-sensitive": false
Hint. If you’re new to creating attributes by using JSON, you might want to use the /config/{appId}/entityTypes/{entityType}/attributes/{attribute} endpoint and the GET method to return the JSON description for an attribute or two. You can then use those JSON descriptions as a template for creating your own attributes.

We should also add that, even though we only defined two attributes in our sample JSON file, the resulting entity type will have six attributes:

  • name
  • description
  • id
  • uuid
  • created
  • lastUpdated

That's because the last four attributes in the list (id, uuid, created, and lastUpdated) are system-generated attributes automatically added to all new entity types. Furthermore, these attributes can’t be copied, deleted, or modified; notice how there’s no way to access any of those functions in Console:

As soon as you have a valid JSON file you can create a new entity type by completing the following procedure:

  1. Click Create and then click Entity Type:
  2. In the subsequent dialog box, click Import JSON:

That brings up the following dialog:

This dialog offers several options for copying your JSON file. To begin with, you can simply drag and drop your file onto the dialog; the JSON will be copied from the file and displayed onscreen:

If dragging and dropping isn’t really your thing then click Upload a File and select the file containing your JSON:

And if you don’t like that option either, just click Paste in your own JSON to display this dialog:

You can then paste in the code copied from your JSON file.

Note. You can also type JSON directly into the dialog box. To be honest, the dialog box probably isn’t the best JSON editor ever made. However, the dialog box does do one thing quite nicely: it validates your JSON before it lets you proceed. In fact, the Next button won’t activate unless you’ve entered a valid JSON string. The dialog can’t tell you if the attribute is correct (i.e., that you've entered all the required properties and property values). But it will catch any JSON-related errors.

After you’ve entered a valid JSON string, click Next. To create your new entity type, enter a name in the Name field and then click Save:

Just like that, you’ve created a new entity type.