1. Prerequisite Knowledge

Prerequisite Knowledge

To use Stubber effectively, you will need to familiarize yourself with JSON, JSONata, and the concept of data substitution to configure your templates.

JSON

What is JSON

JSON stands for "JavaScript Object Notation." It is a lightweight data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. You might be familiar with JSON as a means to transmit data between a server and a web application. JSON is a text format that consists of key-value pairs, where each key is a string and each value can be a string, number, boolean, null, array, or another JSON object. Here's a simple example of JSON:

        {
  "name": "John Doe",
  "age": 30,
  "isStudent": false,
  "grades": [90, 85, 92],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "zipcode": "12345"
  }
}

      

In this example, there are key-value pairs representing various pieces of information about a person. The keys are strings (e.g., "name," "age"), and the values can be strings (e.g., "John Doe"), numbers (e.g., 30), booleans (e.g., false), an array (e.g., [90, 85, 92]), or even null or objects.

How to Use JSON in Stubber

In the Stubber interface, JSON is used specifically for configuring the different components or aspects of the flow. This is done in Stubber's native JSON editor. Here's an example of an item being configured in the Stubber JSON editor:

loading...

In the above example, we have a fields object where a field of type "text" is configured with the name and key set to "name."

Variable Substituition

In Stubber, variable substitution is a powerful feature used when you need to reference a data point dynamically within your process. This functionality allows for flexibility and adaptability, making your flows more responsive to changing conditions.

What is Variable Substitution

  • Variable substitution enables you to dynamically reference specific data points within your flow.
  • Instead of using static values, you can leverage variables or placeholders that get replaced with actual data during the execution of a stub.
  • Use data substitution to enhance the flexibility of your flows, allowing them to adapt to varying scenarios without requiring manual adjustments.

Example Scenario

Consider a scenario where you want to send personalized messages to students with their latest marks. Suppose the flow we build has the following data structure:

        {
  "name": "John Doe",
  "age": 30,
  "isStudent": false,
  "grades": [90, 85, 92],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "zipcode": "12345"
  }
}

      

Instead of hardcoding names and marks, which might differ from stub to stub, you can use variable substitution:

        Hello, {name}! Your latest grade is {grades[0]}.

      

During the execution of the stub, Stubber replaces the placeholders with the actual values, ensuring each message is personalized and specific.

For further information, you can refer to this source.

JSONata

What is JSONata

JSONata provides a concise syntax for querying and transforming JSON data. It is particularly useful in Stubber for defining conditions within your flows. In Stubber, we use JSONata to manipulate and extract data from JSON structures with ease. Here, we'll cover some fundamental aspects, focusing specifically on basic conditionals.

Conditional Expressions using comparison operators:

Employ comparison operators like <, >, <=, >=, ==, and != to evaluate conditions.

        {
  "result": grades[0] > 50 ? "Passed" : "Failed"
}

      

Here, we are checking whether the grade is above 50. If it is, we store the result as "Passed"; otherwise, it is stored as "Failed."

Further Resources

These basics provide a glimpse into the power of JSONata for creating conditional expressions within your Stubber flows. For more in-depth information and advanced usage, we recommend referring to the official JSONata documentation. There, you'll find comprehensive guides and examples to master the capabilities of JSONata.