writeJson
Overview
The writeJson logic is a powerful utility designed to serialize input data into JSON format and save it to a specified location in Google Drive, particularly to the "Intuidy" folder. This functionality is crucial for applications that need to export or share structured data in a widely accepted format such as JSON.
Settings
The writeJson logic includes several configurable settings that affect its behavior and output. Below is a comprehensive description of each setting:
1. fileName
- Input Type: String
- Description: This setting defines the name of the file that will be created in Google Drive. If not specified, the default value is
'export.json'. Modifying this value allows users to customize the file name for better organization or identification of data exports. - Default Value:
'export.json'
2. subfolder
- Input Type: String (optional)
- Description: This optional setting specifies the path to a subfolder within the Intuidy directory in which to save the JSON file. This feature allows better organization of files by categorizing them into different subfolders based on project or data type. If the subfolder does not exist, the logic will create it.
- Default Value: None (the file will be saved directly in the Intuidy folder if this setting is not provided)
Inputs
- Input Data: The
writeJsonlogic accepts the following input formats:- Array of Objects: This is suitable for exporting collections of related data, such as user profiles or transaction records.
- Object: A single object can be serialized, enabling the export of detailed records, such as a specific user’s profile or settings.
- String: This allows direct input of string data, which will be treated as JSON if it is correctly formatted.
How It Works
When the writeJson function is called, it performs the following steps:
- It receives the input data, configuration, and context parameters.
- It sets up the configuration for the
writeFileNode, including serializing the input data into JSON format. - It defines the MIME type as
application/json, ensuring compatibility with the JSON format, and specifies that the format is 'json' without converting it to a spreadsheet format. - The function then calls the
writeFileNode, which is responsible for actually writing the serialized JSON data into the specified file within Google Drive.
The logic is asynchronous, implying that it can handle other tasks while waiting for Google Drive operations to complete, thereby improving efficiency.
Use Cases & Examples
Use Case 1: Data Export for Reporting
A business analytics team may need to regularly export large datasets of customer interactions for reporting purposes. Using writeJson, they can automate this process, ensuring data is always up-to-date and structured correctly.
Use Case 2: Sharing Configuration Data
A software development team may want to share configuration settings or environment variables stored in JSON format with the wider team or stakeholders. This allows easier understanding and modification of settings.
Use Case 3: Data Archiving
Organizations often require archiving logs or transaction data for compliance. The writeJson logic can be utilized to serialize and save these data sets automatically to Google Drive on a scheduled basis.
Detailed Example
Scenario: Automating Customer Data Exports
The marketing department of a company needs to export customer engagement data collected from various campaigns for analysis. They can configure the writeJson logic as follows:
{
"inputs": {
"data": [
{"customerID": 1, "engagementScore": 75, "lastEngaged": "2023-10-15"},
{"customerID": 2, "engagementScore": 85, "lastEngaged": "2023-10-18"}
]
},
"config": {
"fileName": "customer_engagement_data.json",
"subfolder": "Marketing/Engagements"
},
"context": {}
}Explanation of Configuration:
inputs.data: An array of customer engagement records that need to be exported in JSON format.config.fileName: The file will be namedcustomer_engagement_data.json, making it easy to identify the contents.config.subfolder: Saves the JSON file in theMarketing/Engagementssubfolder, helping to keep the Google Drive organized.
This configuration allows for automation and consistency in the data export, facilitating efficient data analysis by the marketing team.