Memeputer

Transforms

Transform nodes process data between resources. Use them to extract, format, or manipulate data as it flows through your workflow.

Adding a Transform

  1. Right-click on the canvas or use the + Transform button
  2. Position the Transform node between other nodes
  3. Connect inputs and outputs as needed

Transform Types

Extract

Pull specific fields from JSON data using JSONPath syntax.

Input:

{
  "user": {
    "profile": {
      "name": "Alice",
      "avatar": "https://..."
    }
  }
}

Expression: $.user.profile.name

Output: "Alice"

Template

Format strings using mustache-style templates.

Template:

Hello {{name}}! Your order #{{orderId}} is {{status}}.

Input:

{
  "name": "Alice",
  "orderId": "12345",
  "status": "ready"
}

Output: Hello Alice! Your order #12345 is ready.

JavaScript

Run custom JavaScript code for complex transformations.

// Access input data
const { items, discount } = input;

// Process
const total = items.reduce((sum, item) => sum + item.price, 0);
const finalPrice = total * (1 - discount);

// Return output
return {
  itemCount: items.length,
  subtotal: total,
  discount: discount * 100 + "%",
  total: finalPrice.toFixed(2),
};

Common Use Cases

Extracting API Responses

Many APIs return nested data. Extract what you need:

// Extract image URL from generation response
return {
  imageUrl: input.data.artifacts[0].url,
  prompt: input.data.prompt,
};

Formatting for Social Posts

Prepare content for posting:

const { brief, captions } = input;

return {
  postText: captions[0].text,
  hashtags: brief.keywords.map((k) => "#" + k).join(" "),
  fullPost: `${captions[0].text}\n\n${hashtags}`,
};

Conditional Routing

Choose different paths based on data:

const score = input.analysis.sentiment_score;

if (score > 0.7) {
  return { path: "positive", action: "celebrate" };
} else if (score < 0.3) {
  return { path: "negative", action: "escalate" };
} else {
  return { path: "neutral", action: "standard" };
}

Data Validation

Check data before passing to expensive resources:

const { prompt, style } = input;

if (!prompt || prompt.length < 10) {
  throw new Error("Prompt must be at least 10 characters");
}

if (!["realistic", "artistic", "minimal"].includes(style)) {
  throw new Error("Invalid style option");
}

return { prompt, style, validated: true };

Available Globals

In JavaScript transforms, you have access to:

VariableDescription
inputData from connected upstream nodes
consoleFor debugging (logs to browser console)
JSONFor parsing/stringifying JSON
MathMathematical operations
DateDate/time operations

Error Handling

If a transform throws an error:

  1. The workflow execution stops
  2. The error is displayed on the Transform node
  3. The Output node shows the error state

To handle errors gracefully:

try {
  const result = riskyOperation(input);
  return { success: true, data: result };
} catch (error) {
  return { success: false, error: error.message };
}

Performance Tips

  • Keep transforms simple and focused
  • Avoid expensive operations (large loops, complex regex)
  • Use Extract for simple field access (faster than JavaScript)
  • Split complex logic into multiple Transform nodes for debugging