Use JSON to generate a vocabulary
- Last Updated: September 20, 2021
- 5 minute read
- Corticon.js
- 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.
- In Corticon.js 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—Each attribute takes the JSON Element Name that was in the source JSON. The root
entity has five attributes that are added as attributes of
Root. You can manually revise the data type as appropriate. 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, and specify their JSON Path as
relative to the root:

- 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 shows that
productsis 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.js, 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.
|
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.js 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.
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.
![]()