JSON Generator

Discover more about the JSON Generator connector and how to use it on the Digibee Integration Platform.

JSON Generator creates a JSON object. This connector accepts any input.

Parameters

Take a look at the configuration options for the connector. Parameters supported by Double Braces expressions are marked with (DB).

Parameter
Description
Default value
Data type

JSON (DB)

The JSON object that will be the output of the connector.

N/A

JSON Object

Fail on Error

If the option is activated, the pipeline's execution with an error will be interrupted. Otherwise, the pipeline execution proceeds, but the result will show a false value for the "success" property.

False

Boolean

Using Global variables

Global variables can be retrieved in the JSON Generator connector using the following Double Braces expression:

{{global.global-name}}

You can retrieve Globals in two ways:

  • As a string

  • As a number

Retrieving Global variables as a string

If the Global variable’s value is a string, regardless of its category, you must enclose the Double Braces expression in double quotes.

For example, suppose you create a Global named global-email under the Email category and set an email address as its value. The Platform will interpret this value as a string. Therefore, to retrieve this Global variable in the JSON Generator connector, structure the expression as follows:

{
	"email": "{{global.global-email}}"
}

If you don’t enclose the expression in double quotes, you will receive the following error:

This rule applies to any Global variable with a string value.

Retrieving Global variables as a number

If the Global variable’s value is a number, don’t enclose the Double Braces expression in double quotes. Otherwise, the number will be treated as a string.

For example, suppose you create a Global named global-id under the ID category and set its value to 1234.

To retrieve this Global variable as a number in the JSON Generator connector, structure the expression as follows:

The output will be:

However, if you need to retrieve it as a string, simply enclose the expression in double quotes:

This will return:

Using mocks

You can use mocks to define multiple example payloads with hardcoded values and simulate different input scenarios without modifying your pipeline. Mocks are available when building pipelines, capsules, and in Test Cases.

Read the documentation to know more about Connector Mocking.

circle-info

Mock fields do not support Double Braces expressions. All values must be hardcoded.

Creating a mock response

Mock responses for the JSON Generator connector must be created through the configuration form. Creating mocks from the connector's execution output is not supported for this connector.

  1. Open the connector's configuration form.

  2. To create your first mock, click Set new in the Create Mock Response option.

  3. Enter the payload in the JSON Body field.

  4. Enter a Name for the mock response.

  5. Click Add new.

To add more mocks after the first one, click the pencil icon next to the mock list. A sidesheet opens with an Add new form at the bottom where you can configure additional mock responses.

Creating multiple mocks

You can create multiple mocks to represent different scenarios. Once created, each mock can be enabled or disabled individually using its toggle. Only one mock per connector can be active at a time. When a mock is active, the connector displays an M badge in the flow tree.

Running a pipeline with an active mock

When you run the pipeline with a mock active, the JSON Generator connector is replaced by the mock payload at runtime. The rest of the pipeline receives the mock output as if it were the connector's actual output.

Usage examples

Modifying data

In this example, we used the JSON Generator connector to modify someone’s data. Here, we want to join the firstName and lastName properties into a single property called fullName. We also want to delete the phoneNumber property and add a property called country, which has the value “Brazil”.

Input

Parameter settings

We use the JSON Generator connector with the following JSON parameter configuration:

Here, we used the CONCAT Double Braces function to join the first and last names, with a blank space between them.

Output

Mock usage example

In this example, we used the mock feature to test two different order states in the same pipeline without modifying the JSON parameter each time.

The pipeline processes incoming orders and routes them based on their status. During development, we want to verify that the routing logic works correctly for both a completed order and a pending order.

Mock configuration

Instead of editing the connector's JSON parameter on every test run, we created two mock responses, each representing a different scenario.

Mock 1 — name: "completed-order"

Mock 2 — name: "pending-order"

To create the first mock, open the connector's configuration form, click Set new in the Create Mock Response option, fill in the JSON Body, enter a name, and click Add new.

To add the second mock, click the pencil icon next to the mock list and use the Add new form at the bottom of the sidesheet.

Testing each scenario

To test the completed order flow, enable the Mock Response switch in the connector configuration form, select completed-order from the dropdown, and confirm the updates on the connector. The JSON Generator will display the M badge in the flow tree, confirming that the mock is active.

When you run the pipeline, the downstream connectors receive the Mock 1 payload instead of the connector's actual JSON output.

To test the pending order flow, go back to the configuration form, select pending-order from the dropdown, and save again. Only one mock can be active at a time. To switch scenarios, select a different mock from the dropdown and save the configuration form.

When you deploy the pipeline, mock responses are automatically ignored. You don't need to deactivate them before deploying.

Output (completed-order active)

Output (pending-order active)

Last updated

Was this helpful?