Xano Contributors

Xano Contributors

A collaborative platform where developers share, improve, and standardize Xano Actions through community-driven Actions Project. Built on the foundation of open knowledge sharing, it enables newcomers to learn from proven solutions while giving experienced users a space to establish best practices. With features like project forking, community voting on priorities, and recognition for top contributors, Xano Contributors fosters a vibrant ecosystem where collective expertise accelerates innovation for the entire Xano community.

Actions (1)
A utility designed to clean and format JSON data, making it ideal for use in prompts for Large Language Models (LLMs) like those from OpenAI, Google AI, Anthropic, and others. It processes a JSON object, intelligently removes keys that have empty or null values, and then returns a clean, human-readable, YAML-like string. This process helps reduce the token count sent to the AI service (saving costs) and improves the clarity of the prompt, often leading to better AI-generated responses. Example Use Cases: Agent and MCP tool outputs Agent Inputs (Prompts and System Prompts) Inputs This action accepts two inputs: | Name | Type | Required | Description | | -------------------- | ------- | :------: | ---------------------------------------------------------------------------------------------------------------------------------------- | | payload | json | Yes | The JSON object you want to process and clean. | | stripemptykeys | bool | Yes | A boolean flag to control the cleaning process. If true, keys with empty values will be removed. If false, the payload will be formatted without removing any keys. | Functionality Breakdown The action follows a clear, step-by-step process to transform the input payload: Pre-check: First, the action ensures the provided payload is not null to prevent execution errors. Initialization: It creates a new, empty object (cleaned_payload) to store the filtered results. This is a best practice that avoids modifying the original input object. Iteration: The action then iterates through each key-value pair (entry) of the input payload. Empty Value Check: For each entry, it performs a comprehensive check to determine if the value (entry.value) is "empty." This is accomplished using the following Xano expression: ` ($entry.value == null) || (($entry.value|istext) && ($entry.value|strlen) == 0) || (($entry.value|isarray) && ($entry.value|count) == 0) || (($entry.value|is_object) && ($entry.value|count) == 0) ` This expression identifies a value as empty if it meets any of these conditions: The value is null. The value is a text string with a length of zero (e.g., ""). The value is an array with zero items (e.g., []). The value is an object with zero key-value pairs (e.g., {}). Conditional Filtering: If a value is NOT empty (the expression in step 4 evaluates to false), the original key-value pair is added to the cleaned_payload object. If a value IS empty (the expression evaluates to true), it is skipped and not included in the final result. Final Output Formatting: After the loop has processed all items, the action encodes the cleaned_payload object into a formatted string that approximates the YAML format (e.g., key: value). This string is the final, optimized output. Example Usage Example 1: Stripping Empty Keys (Standard Use) This example demonstrates the primary use case where you want to clean up the data. Input: `json { "payload": { "name": "Daniel", "email": "daniel@example.com", "bio": "", "last_login": null, "preferences": {}, "tags": [] }, "stripemptykeys": true } ` Output: `text name: Daniel email: daniel@example.com ` Explanation: The bio, last_login, preferences, and tags keys were all removed because their values met the criteria for being "empty" as defined in step 4 of the Functionality Breakdown. Example 2: Retaining All Keys This example shows what happens if you set stripemptykeys to false. The action will simply format the original payload without removing anything. (Note: This assumes a conditional branch in your function stack that bypasses the stripping logic based on the boolean input). Input: `json { "payload": { "name": "Daniel", "status": null }, "stripemptykeys": false } ` Output: `text name: Daniel status: null ` Explanation: Because stripemptykeys was false, the cleaning logic was bypassed, and all key-value pairs from the original payload were included in the formatted output string.
AI
Updated 16 hr ago