Skip to main content

Encoding Utilities

Encode, decode, and transform data within your workflows using Torq’s built-in Encoding utility steps.

Updated this week

Torq’s Encoding utilities perform common format and conversion operations, such as converting between CSV/JSON/YAML, encoding or decoding Base64, Hex, and URLs, and rendering content like Markdown into HTML, plain text, or PDF.

Conversion

Convert CSV to JSON

Converts CSV text into a JSON object.

Input

a,b,c,d
1,2,3,4
5,6,7,8

Output

{
"result": [
{
"a": "1",
"b": "2",
"c": "3",
"d": "4"
},
{
"a": "5",
"b": "6",
"c": "7",
"d": "8"
}
]
}

Convert EML to JSON

Converts an EML email file into a structured JSON object.

Input

From: Diana Leib <diana.leib@twistt.io>
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\))
Subject: New email
X-Universally-Unique-Identifier: D82FDA18-F522-4E4D-AF27-D93330929636
Message-Id: <78R6L98-3FFA-4B9C-906C-91FC54E3B3FE@twistt.io>
Date: Thu, 6 Oct 2022 16:33:00 +0300
To: Ulysses Bedford <ulysses.bedford@twistt.io>
Content here

Output

{
"result": {
"headers": {
"Content-Transfer-Encoding": "7bit",
"Content-Type": "text/plain; charset=us-ascii",
"Date": "Thu, 6 Oct 2022 16:33:00 +0300",
"From": "Diana Leib <diana.leib@twistt.io>",
"Message-Id": "<78R6L98-3FFA-4B9C-906C-91FC54E3B3FE@twistt.io>",
"Mime-Version": "1.0 (Mac OS X Mail 16.0 \\(3696.120.41.1.1\\))",
"Subject": "New email",
"To": "Ulysses Bedford <ulysses.bedford@twistt.io>",
"X-Universally-Unique-Identifier": "D82FDA18-F522-4E4D-AF27-D93330929636"
},
"text": "This is the content of the email",
"html": "",
"attachments": [],
"inline_objects": []
}
}

Convert JSON to TOON

Converts a JSON object into Token-Oriented Object Notation (TOON) to reduce token usage when passing structured data to AI models.

TOON flattens JSON into a compact, readable format, helping optimize prompts and lower token consumption during LLM calls.

Input

{
"user": {
"id": 123,
"name": "Alice",
"roles": ["admin", "analyst"]
}
}

Output

user.id=123
user.name=Alice
user.roles[0]=admin
user.roles[1]=analyst

Convert JSON to YAML

Converts a JSON object into YAML.

Input

{
"outer_key": {
"inner_key": [1, 2, 3]
}
}

Output

outer_key:
inner_key:
- 1
- 2
- 3

Encoding and decoding

Decode Base64

Decodes a Base64-encoded string.

Input

c2FtcGxlIGVuY29kZWQgYmFzZTY0IHN0cmluZw==

Output

sample encoded base64 string

Decode Hex

Decodes a hexadecimal string into plain text.

Input

73616d706c652068657820656e636f64656420737472696e67

Output

sample hex encoded string

Decode JSON

Decodes a JSON string and returns a JSON object.

Input

"{\\"a\\":1,\\"b\\":2}"

Output

{
"result": {
"a": 1,
"b": 2
}
}

Decode URL

Decodes a URL-encoded string.

Input

http%3A%2F%2Fapi.plos.org%2Fsearch%3Fq%3Dtitle%3A%22Drosophila%22+AND+body%3A%22RNA%22%26fl%3Did%2Cabstract

Output

http://api.plos.org/search?q=title:\"Drosophila\" AND body:"RNA"&fl=id,abstract

Encode Base64

Applies Base64 encoding to a given string.

Input

Encode this base64 string

Output

RW5jb2RlIHRoaXMgYmFzZTY0IHN0cmluZw==

Encode Hex

Encodes a string into hexadecimal.

Input

sample hex encoded string

Output

73616d706c652068657820656e636f64656420737472696e67

Encode URL

Encodes a URL into a safe, URL-encoded string.

Input

<http://api.plos.org/search?q=title:"HW"> AND body:"RNA"&fl=id,abstract

Output

http%3A%2F%2Fapi.plos.org%2Fsearch%3Fq%3Dtitle%3A%22HW%22+AND+body%3A%22RNA%22%26fl%3Did%2Cabstract

Markdown

Markdown to HTML

Converts markdown text into HTML.

Input

# Incident Report

This is a markdown report generated by Torq.

- Severity: High
- Status: Open

Output

<h1>Incident Report</h1>
<p>This is a markdown report generated by Torq.</p>
<ul>
<li>Severity: High</li>
<li>Status: Open</li>
</ul>

Markdown to PDF

Renders markdown content into a PDF file.

Input

# Incident Report  This is a markdown report generated by Torq.

Output

PDF file generated from the markdown input.

Markdown to Plain Text

Converts markdown into plain text by stripping formatting.

Input

# Incident Report

This is a markdown report generated by Torq.

- Severity: High
- Status: Open

Output

Incident Report

This is a markdown report generated by Torq.

Severity: High
Status: Open

Use case: Encode and Decode Base64

Automatically convert NDJSON responses into a standard JSON array using Torq’s Encoding Utilities. This is useful when security or observability tools return results as newline-delimited objects, but your next steps require a valid JSON array for looping, filtering, or enrichment.

For a detailed implementation, refer to the full workflow template available in Torq.

  1. Provide NDJSON as Base64 input: Configure the nested on-demand trigger to accept an ndjson_input parameter. The workflow expects the NDJSON payload to be Base64-encoded (for example using
    {{ b64enc $.step_with_ndjson_output.result }}), ensuring safe transport and consistent parsing.

  2. Decode the payload: Use the Decode Base64 utility to convert the incoming Base64 string back into raw NDJSON text.

  3. Transform NDJSON into a JSON array: Replace newline separators between objects with commas, then trim any trailing comma. This produces a single comma-separated list of JSON objects.

  4. Decode into standard JSON: Wrap the comma-separated content in square brackets ([ ... ]) and use Decode JSON to return a valid JSON array. The workflow outputs formatted_json, ready for downstream steps like loops, filters, or enrichment.

Output:

Instead of:

{"id":1,"name":"a"}
{"id":2,"name":"b"}

You get:

[
{"id":1,"name":"a"},
{"id":2,"name":"b"}
]

Troubleshooting

Utility steps fail with Context Deadline Exceeded error

When running workflows that use Encoding utility steps, especially steps such as Encode URL, Decode URL, or steps that accept URL-based input, you may encounter the following error:

context deadline exceeded(Client.Timeout exceededwhile awaiting headers)

This error occurs when the step attempts to resolve the URL automatically and cannot reach the host, causing the operation to time out. In most cases, you do not want the step to attempt to fetch or resolve the URL; you only want it to process the text.

Symptom

A workflow step fails with an error similar to:

{
"step_status":{
"code":2,
"message":"failed parsing environment variables",
"verbose":"env: parse error on field \"FileInput\" of type \"files.File\": Get \"http://someurl.com\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)"
}
}

This indicates the step is trying to interpret the URL input as a file or attempting to resolve it externally.

Cause

By default, some encoding utility steps attempt to determine whether an input value is a file. When the input is a URL, the system may try to reach the URL to validate it, leading to a timeout if the domain is unreachable or blocked.

Resolution

Option 1 (recommended): Set the input data type to Plain text

All Encoding Utility steps allow you to choose how the input is parsed. To prevent URL resolution entirely, keep the input data type set to Plain text (default).

Option 2: Enable the hidden “Do not parse as file” parameter (YAML edit)

To prevent the step from attempting to resolve the URL, you can enable a hidden parameter that instructs the step not to treat the input as a downloadable file.

  1. Open the step in YAML editor:

    1. Click the three dots (…) in the top-right corner of the step’s Properties panel.

    2. Select Edit YAML.

  2. Add the hidden parameter:

    1. Locate the env: section. For example:

      env:
      INPUT:"##{{ $.url.variable }}"
    2. Add the following line immediately under it:

      env:
      INPUT:"##{{ $.url.variable }}"
      DO_NOT_PARSE_AS_FILE:"true"
    3. Click Save.

  3. Confirm the new parameter appears: After saving, you'll see a new parameter in the step: Do not parse as file > true This confirms the configuration change is active.

  4. Publish the workflow.

Did this answer your question?