# Escape string

## Description

This operation is used to encode or "escape" characters in a string so that they can be safely used in different contexts, such as URLs, JSON, HTML, or code. This operation is helpful when you need to format text with special characters in a way that won’t break syntax or cause unintended effects in various data formats.

***

## Data types

These are the input/output expected data types for this operation:

### Input data

![](/files/lPHCVhp93aYrWgLIlhNp) - Strings with the characters you want to escape.

### Output data

![](/files/lPHCVhp93aYrWgLIlhNp) - Strings with the required escaped characters.

***

## Parameters

These are the parameters you need to configure to use this operation (mandatory parameters are marked with a <mark style="color:red;">**\***</mark>):

<details>

<summary>Escape Level<mark style="color:red;"><strong>*</strong></mark></summary>

Choose how to control the extent of character escaping applied to the input. Select one of the following:

* **special chars** - Escapes only a specific set of characters that have special meanings in the chosen format.
* **everything -** Escapes all characters that could potentially have any impact in the selected format, including less common or optional characters.
* **minimal** - Escapes only the characters that are strictly necessary to make the string safe for the specific format.&#x20;

Check below some examples of different input messages and how they would be affected by each escape level option:

**JSON – Special Characters Escape Level**

In addition to the minimal set (`"`, `\`, control characters), it may include:

* Unicode characters (e.g., `\u2028`, `\u2029`)
* Any non-ASCII characters: `é`, `©`, etc., escaped as `\u00E9`, `\u00A9`

{% code title="Example" %}

```json
jsonCopyEdit"message": "Caf\u00e9 \u00a9 2025"
```

{% endcode %}

**HTML – Special Characters Escape Level**

In addition to minimal (`<`, `>`, `&`, `"`, `'`), it may escape:

* All punctuation: `!`, `#`, `$`, `%`, `*`, `=`, `+`, `?`, `@`
* Spaces: as `&#32;` or `&nbsp;`
* Non-breaking hyphens, dashes, etc.

{% code title="Example" %}

```html
htmlCopyEdit<p>10 &times; 20 = 200 &euro;</p>
```

{% endcode %}

**XML – Special Characters Escape Level**

Similar to HTML, with strong emphasis on:

* All reserved XML chars: `&`, `<`, `>`, `'`, `"`
* Also can escape all non-ASCII and control characters (e.g., `&#169;` for ©)

**URI / URL Encoding**

* Escapes all characters except unreserved (`A-Z`, `a-z`, `0-9`, `-`, `_`, `.`, `~`)
* Escaped using `%HH` notation (hex value)

{% code title="Example" %}

```
perlCopyEditHello World! → Hello%20World%21
```

{% endcode %}

**JSON (Minimal Escape)**

* `"` (double quote) because it delimits strings
* `\` (backslash) because it’s used as an escape character
* Control characters: `\b`, `\f`, , ,&#x20;

{% code title="Example" %}

```json
jsonCopyEdit{ "message": "He said: \"Hello!\"" }
```

{% endcode %}

**HTML (Minimal Escape)**

* `<` – to prevent tag injection
* `>` – to prevent broken tags
* `&` – to prevent character entity confusion
* `"` – if used inside attribute values wrapped in double quotes
* `'` – if used inside attribute values wrapped in single quotes

{% code title="Example" %}

```html
htmlCopyEdit<a href="page.html?msg=Hello &amp; Welcome">Link</a>
```

{% endcode %}

**XML (Minimal Escape)**

* `<`, `>`, `&`, `'`, `"` – for both content and attribute values

</details>

<details>

<summary>Escape Quote<mark style="color:red;"><strong>*</strong></mark></summary>

This parameter lets you specify how to handle quote characters (`"` and `'`) within the input text. Enter one of the following:

* **single** - Escapes only single quotes (`'`) in the input.
* **double** - Escapes only double quotes (`"`) in the input.
* **backtick** - Escapes only backticks (`` ` ``) in the input.

</details>

<details>

<summary>JSON compatible</summary>

Set this parameter to **true** if you need to use the output string in a JSON. This ensures that any characters with special meanings in JSON are escaped properly, allowing the resulting string to be safely embedded in JSON objects or arrays.

</details>

***

## Example

Suppose you want to **escape characters** that are between `"` in a series of input strings. To do it:

1. In your Pipeline, open the required [Action](/the-workspace/pipelines/actions.md) configuration and select the input **Field**.
2. In the **Operation** field, choose **Escape String**.
3. Set **Escape Level** to `special chars`.
4. Set **Escape Quote** to `double`.
5. Set **JSON compatible** to `false`.
6. Give your **Output field** a name and click **Save**. Matching characters will be escaped. For example:

```
Input data - "She said, "Hello, world!""

Escape Level - special chars

Escape Quote - double

JSON compatible - false

Output data - "She said, \"Hello, world!\""
```

{% hint style="info" %}
You can try out operations with specific values using the **Input** field above the operation. You can enter the value in the example above and check the result in the **Output** field.
{% endhint %}


---

# 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.onum.com/the-workspace/pipelines/actions/transformation/field-transformation/field-transformation-operations/control-characters/escape-string.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.
