> For the complete documentation index, see [llms.txt](https://docs.digibee.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digibee.com/documentation/connectors-and-triggers/connectors/tools/json-generator.md).

# 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](/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/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**

Never enclose a Double Braces expression in double quotes when the value is a string. The connector resolves a string together with its quotes, so wrapping the expression produces two sets of quotes and the template no longer parses.

For example, suppose you create a Global named **global-email** under the **Email** category and set an email address as its value. Reference it without quotes:

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

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

```json
{
  "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: Unexpected character ('A' (code 65)): was expecting comma to separate Object entries",
  "code": 500
}
```

The error shows the template after substitution — the value arrives with its own quotes, so a quoted expression produces two sets.

This rule applies to every parameter that holds a serialized JSON document, including the **body** of the REST connector.

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

Read the documentation to know more about [Connector Mocking](/documentation/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" %}

```json
{
"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" %}

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

{% endcode %}

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

#### **Output**

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

```json
{
"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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
