Data to JSON(String)
This component converts various types of data, such as objects, lists, dictionaries, or messages, into a JSON string. JSON is a common text format that many systems use to store and exchange data. You can use this node to prepare your data for saving, sending to other services, or further processing in your automation workflows.
How it Works
This component acts as a translator for your data. When you connect data to it, the component analyzes the input. It supports multiple formats, including lists, single items, and structured data.
If the input contains complex items like dates or special codes, the component safely converts them into text to ensure the final result is always valid JSON. If you provide no data, it returns an empty list. The result is always a text string containing the structured JSON data, ready to be used by other parts of your workflow.
Inputs
This component features Mapping Mode. When you enable this mode, you can control the input more dynamically. You have three options:
- Fixed: Enter the data directly.
- Mapped: Connect the output of another component.
- Javascript: Write code to calculate the value on the fly.
Input Fields
- Data: The Data object, list, dictionary, string, or message you want to convert. This field accepts various data structures and can handle lists of items.
Outputs
The component outputs a JSON string. This is a text representation of your input data in JSON format. You can connect this output to other nodes that require data in JSON format, such as API senders, database savers, or parsers.
Output Data Example (JSON)
json { “id”: “12345”, “name”: “Sample Item”, “active”: true, “tags”: [“automation”, “nappai”], “metadata”: { “created”: “2024-01-01” } }
Connectivity
Connect the Data input from data sources like database extractors, file readers, message processors, or any node that produces structured data.
Connect the JSON output to nodes that need structured text data, such as:
- HTTP Request Senders: To send data to external APIs.
- File Writers: To save data as a JSON file.
- Database Nodes: To store structured records.
- AI Assistants: If the AI model expects JSON input.
Usage Example
Imagine you have a workflow that fetches user information from a database. The data comes back as a complex object. You want to save this as a file or send it to an external service.
- Connect the database node to this component’s Data input.
- Connect the JSON output of this component to a “Write to File” node or an “HTTP Request” node.
- The component converts the database records into a JSON string, making it ready for saving or sending.
Tips and Best Practices
- This component automatically handles lists. You can pass multiple items at once, and they will be processed together.
- It is resilient to complex data. If your input has dates or unique identifiers, they will be converted to strings automatically without breaking the flow.
- Use Mapping Mode to make your workflows more flexible by dynamically setting inputs based on other components.
- This component ensures that the output is always a valid JSON string, even if the input contains unusual data types.
Security Considerations
This component processes data locally within the workflow. Ensure that the data you feed into this component comes from trusted sources to maintain the integrity and safety of your automation.