1. Prerequisite Knowledge

Prerequisite Knowledge

To use Stubber, you will need to be familiar with JSON, JSONata, and the concept of data substitution for configuration.

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 familar with JSON as 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," "New York"), 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 specificially for configuring the different components or aspects of the flow. This is done in Stubber's native JSON editor. Here's a an example of an item that is being configured in the Stubber JSON editor:

loading...

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

Data 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 that 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 and if so then we want store the result as "Passed" else 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.