Use JSON to generate a vocabulary
- Last Updated: July 3, 2024
- 5 minute read
- Corticon
- Version 7.2
- Documentation
Create a Vocabulary from a JSON payload
Suppose you are writing rules for a B2B e-commerce application that will determine what, if any, discounts should be applied to an order. An order contains contact information about the customer, their partnership status ('elite' or 'standard') and the items in the order. Your rules will examine this information to determine a discount rate for the order in line with the promotions being offered by your company. For example, 'elite' customers might get 15% off on orders over $10,000.
Working with IT, you've been supplied this sample JSON file representing an order. JSON in this format is used by other components of your e-commerce application:
|
To populate a Vocabulary from a JSON payload:
- Copy the preceding JSON and then save in a temporary file. Set the
file extension to
.json. - In Corticon Studio, create a new Rule Project named
OnlineRetail. - In the project, create a Vocabulary named
Orders. - Click in the Vocabulary edit window, and then select Vocabulary > Populate Vocabulary from JSON.
- Choose the temporary file with the JSON you saved, and then click Open.
The Vocabulary that the JSON generates is the following:
Let's take a closer look at the Vocabulary:
- Root entity—The JSON source has an object
definition at root, indicated by the JSON starting with initial brace. You know this
root entity is an order. Corticon does not know that, so it named the top-level
entity
Root. After vocabulary generation completes you can refactor the root entity name toOrder:
- Attributes—The
ShippingAddressentity, renamedOrder, has six attributes.- The values in the source data were suggested as dates, numbers, and Strings. Review each one, and revise each attribute's data type as appropriate.
- Each attribute will store the name:
- If the name in the source JSON is valid, no value is copied into the JSON Element Name field in the Vocabulary.
- If the name in the source JSON is not valid, an
override is attempted, and added to the vocabulary
while the JSON Element field stores the source name. In this example, the
source has an element named
street address1. As spaces are not valid in Corticon names, the namestreet_address1with an underscore is inferred, and the JSON Element Name is assignedstreet address1. This is the incoming payload identifier that will map to its Vocabulary attribute name:
Note: If an attribute has a null value in the source JSON, the data type String is assumed.
- Non-root entities—Other entities take the
name in the source JSON:

- Associations: Corticon added the
Productsentity, and then added an association fromRoot (Order)toproducts:
- Scalar arrays—A scalar array is handled as
an association from the entity with its own identifying Entity. The JSON Array's
relationship is that
productsare relative to root ($) and one or moretagsare related toproducts:
"A": [1,2,3, {"B": {"color" : "red"}}]This
JSON snippet defines an array "A" containing the
scalar values 1,2,3 and the object "B". In Corticon, an array must be either all scalar
values or all objects. Update a vocabulary from a JSON payload
Suppose your Sales department wants to enhance the discount program to provide an additional discount to government agencies and whether an order is marked for expedited handling. In support of this IT has provided an updated sample JSON the includes the new information.
An update generates new entities, attributes, and associations. The
existing entities, attributes, and associations are not revised by regenerating over the
existing Vocabulary. If you want one element to be regenerated, delete it before you
perform the update. You could even delete the vocabulary entirely, and then start fresh.
The original sample payload adds a requirement for Billing
Address to the sampleCustomer
Vocabulary.
|

Root was refactored to
Order, so Root will be deleted.Integrating multiple sources into a Vocabulary
To build a single vocabulary that integrates multiple data feeds, it is convenient to import additional sources into separate vocabulary domains. Corticon enables you to import into an added domain without impacting the rest of the Vocabulary.
Consider a variation on the customer info so that it identifies a partner:
|
Partners. Choose the file where the preceding listing was saved, and click Open.
The data is added to the Vocabulary.
Refactor Root to a preferred name, in this example,
Partners: ![]()
Note that a reference to an attribute in an added domain requires the
domain as a qualifier of the attribute when used in rules. In this example, the regular
ShippingAddress.address1 in a Rulesheet would be
differentiated from Partners.ShippingAddress.address1.
![]()