Skip to main content
All CollectionsBuild AutomationsOperators
Data Transformation Operator: Manipulate Data Seamlessly with Torq
Data Transformation Operator: Manipulate Data Seamlessly with Torq

Learn how Torq's Data Transformation operator streamlines JSON manipulation with AI-driven natural language prompts.

Updated this week

Torq's Data Transformation operator streamlines JSON handling, ensuring seamless data interoperability for robust workflows. It uses JQ, a high-performance language for processing and transforming JSON, to perform the transformations during workflow executions.

A visual tool guides users in defining data transformations through multiple instructions, each representing a phase of the transformation, with real-time previews of each outcome. Instructions are piped, allowing the output of one to seamlessly feed into the next, enabling efficient, multi-instruction transformations within a single operator.

Powered by AI, the operator enables users to define transformations using natural language, which is automatically converted into JQ commands. Once the transformation is defined, the AI’s role ends, and the deterministic JQ code executes consistently in every workflow run. Users can create and edit JQ commands without programming expertise while retaining the flexibility to adjust the code and leverage advanced JQ features.

With Torq's Data Transformation operator, you can perform a wide range of JSON transformations, including:

  • Mapping & Extraction

  • Renaming keys

  • Converting data types

  • Filtering & sorting

  • If/else conditions

  • Math functions

  • and much more!

The Data Transformation operator is available to organizations that have opted into Torq AI features.

As with Torq's other responsible AI products, no data inputted into the Data Transformation operator will be used for training.

How to Use

Break down complex data extraction and transformation tasks into smaller micro-transformations with step-by-step instructions. The operator combines these, simplifying output creation and allowing edits at any stage.

  1. Add the Operator to the Canvas: Drag the Transform operator onto the canvas.

  2. Set the Input: Pass the input from the workflow context and click Define Transformation.

    • The operator will not work with raw and/or pasted content.

  3. Enter Your Prompt: Write your prompt in natural language in the transformation window that appears.

    • The Data Transformation Operator supports prompts in multiple languages, not just English.

    • When referencing a string, be sure to write case-sensitive.

    • When creating the prompt, you can click on key:value pairs in the input to reference them within the prompt (and the subsequent instructions/code).

    • The more specific your prompt, the more accurate the command generated will be.

  4. Generate and Review Output: Click the Generate icon and review the output JSON.

    • The output cannot be edited from within the transformation window.

    • Ctrl+Z undoes the last command created.

  5. Edit JQ Commands: You can edit a JQ command directly by clicking the Code heading, hovering over the desired command, and selecting the edit icon.

    • Note that after editing the Code, the original natural language Instruction will no longer be editable, as it has been overwritten. The Code, however, will still be editable.

  6. Edit Instructions: You can edit an instruction after generation by hovering over it and clicking the edit icon. Then click the Generate icon, and the Data Transformation operator will rewrite the generated code.

  7. Add More Instructions: Enter additional prompts as needed and review the results. You can create as many instructions as you desire within one operator instance.

  8. Save Your Transformation: Once your output is satisfactory, click Save.

    • If you do not click Save before navigating away from the transformation window, your prompts and generated transformation will not be saved.

  9. Execute the Transformation: After saving, execute the operator to apply the transformation to the input data and utilize the output in subsequent workflow steps.

  10. Edit After Saving: After saving, you can edit the instructions by clicking the step and then Define Transformation. The transformation window will pop up again.

  11. Save as a Custom Step: Optionally, frequently used data transformations can be saved as custom steps (see below).

The Data Transformation operator provides versatile options for data transformation, addressing most use cases comprehensively. For specific, targeted tasks, Torq's Utility steps offer an alternative solution.

Save as a Custom Step

Save your Data Transformation as a custom step to share and reuse throughout your workspace or organization.

  • If you generate a Data Transformation that could apply to multiple workflows or instances, you can save it as a custom step by accessing the three-dot menu at the top right of the operator.

  • The saved custom step will then be accessible in the Custom tab of your Steps Library.

  • You can share the custom step by sharing the workflow it is a part of, enabling its use across any workspace in your organization.

Use Case Examples

The following example demonstrates a five-stage transformation of an audit log.

1. Extraction of Specific Properties

Extract the specified properties from each audit log entry in a list.

Use-Case

Prompt (Instruction)

Output Code (JQ)

Extracting properties with specific key names from a JSON object.

get "department", "email", "action", "IP address", "location", and "eventID"

.[] | {email: .user.email, department: .user.department, action: .action, location: .deviceDetails.location}


​2. Sorting and Filtering

Remove audit log entries that match the specified value for the given key.

Use-Case

Prompt (Instruction)

Output Code (JQ)

Filter data based on conditions.

remove results where"department" is equal to Engineering

.[] | select(.department != "Engineering")

3. Data Aggregation

Group audit log entries by the specified keys and count the number of entries in each group.

Use-Case

Prompt (Instruction)

Output Code (JQ)

Summarize data by calculating counts, sums, averages, or other aggregations.

group by "department", "email", and count how many actions each person took

group_by(.email, .department) | map({email: .[0].email, department: .[0].department, action_count: map(.action | length) | add})

4. String Manipulation

Extract data using string manipulations, including Regex support, and store the result as a new property.

Use-Case

Prompt (Instruction)

Output Code (JQ)

Perform string matching on key values

extract from "email" the text before @ split the text into two using "." as a separator save the first string as a new property first_name

[.[] | .first_name = (.email | split("@")[0] | split(".")[0]) ]

5. Modify JSON format

Modify the output format and include only the specified keys and values.

Use-Case

Prompt (Instruction)

Output Code (JQ)

Restructure or modify the JSON format, such as renaming keys, changing the nesting of objects, or converting objects to arrays.

get results as an array where each element is a key:value pair where the key is first_name and value is action_count

extract key:values from each object

[.[] | {(.first_name): .action_count}]

.[] | to_entries[] | "\(.key):\(.value)”

Additional Example Prompts

Use-Case

Prompt (Instruction)

Output Code (JQ)

Extraction

extract vulnerabilities

.vulnerabilities

Mapping

remove descriptions, weaknesses, configurations, references, and cvssData

map(del(.cve.descriptions, .cve.weaknesses, .cve.configurations, .cve.references, .cve.metrics.cvssMetricV2[].cvssData))

Mapping and Deletion

map cvssMetricV2 fields as fields under the cve parent object and delete metrics

[.[] | .cve += (.cve.metrics.cvssMetricV2[0] // {}) | del(.cve.metrics)]

Conditional If/Else

if baseSeverity equal "HIGH" then change to "10" else if equal "MEDIUM" then change to "6" else if equal "LOW" then change to "3”

[.[] | if .baseSeverity == "HIGH" then .baseSeverity = "10" elif .baseSeverity == "MEDIUM" then .baseSeverity = "6" elif .baseSeverity == "LOW" then .baseSeverity = "3" else . end]

Convert Data Type

convert baseSeverity to number

.[] | .cve.baseSeverity |= tonumber

Math

add averageScore equal to the average of baseSeverity, exploitabilityScore and impactScore

.[] | .averageScore = ((.baseSeverity + .exploitabilityScore + .impactScore) / 3)

Sort

sort by averageScore

sort_by(.averageScore)

Filter

Filter averageScore smaller than 8

.[] | select(.averageScore < 8)

Did this answer your question?