# JSON Generator

**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](/documentation/connectors-and-triggers/double-braces/double-braces-functions.md) 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](/documentation/developer-guide/development-cycle/build-overview/globals.md) 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:

```
{
 	"timestamp": 1738778741919,
"error": "An internal error has occurred. Exception: com.digibee.pipelineengine.exception.PipelineEngineRuntimeException: Could not parse double braces parameter json due to JSON exception: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'email': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (String)\"{\n  \"email\": email@gmail.com\n}\"; line: 2, column: 17]",
 "code": 500
}
```

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:

```
{
	"id": {{global.global-id}}
}
```

The output will be:

```
{
	"id": 1234
}
```

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

```
{
	"id": "{{global.global-id}}"
}
```

This will return:

```
{
	"id": "1234"
}
```

## **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](/documentation/developer-guide/development-cycle/build-overview/canvas/test-cases.md).

Read the documentation to know more about [Connector Mocking](/documentation/developer-guide/development-cycle/build-overview/canvas/mocking.md).

{% hint style="info" %}
Mock fields do not support Double Braces expressions. All values must be hardcoded.
{% endhint %}

#### **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**

{% code overflow="wrap" expandable="true" %}

```
{
"firstName": "Carlos",
"lastName": "Silva",
"phoneNumber": "+55(11)99999-8888"
}
```

{% endcode %}

#### **Parameter settings**

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

{% code overflow="wrap" expandable="true" %}

```
{
"fullName": {{ CONCAT(message.firstName," ", message.lastName) }},
"country": "Brazil"
}
```

{% endcode %}

Here, we used the [CONCAT Double Braces](/documentation/connectors-and-triggers/double-braces/double-braces-functions/string-functions.md#concat) function to join the first and last names, with a blank space between them.

#### **Output**

{% code overflow="wrap" expandable="true" %}

```
{
"fullName": "Carlos Silva",
"country": "Brazil"
}
```

{% endcode %}

### **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"**

```json
{
  "orderId": "ORD-2024-001",
  "customerId": "C-789",
  "status": "completed",
  "total": 299.90
}
```

**Mock 2 — name: "pending-order"**

```json
{
  "orderId": "ORD-2024-002",
  "customerId": "C-456",
  "status": "pending",
  "total": 149.50
}
```

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)**

```json
{
  "orderId": "ORD-2024-001",
  "customerId": "C-789",
  "status": "completed",
  "total": 299.90
}
```

#### **Output (pending-order active)**

```json
{
  "orderId": "ORD-2024-002",
  "customerId": "C-456",
  "status": "pending",
  "total": 149.50
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digibee.com/documentation/connectors-and-triggers/connectors/tools/json-generator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
