Skip to main content
Skip table of contents

File Manipulation - Convert JSON to CSV

Overview

This script converts a .json file to .csv format and optionally drops specified columns. It is designed to run within Alli Workflows and can be used to prepare structured data for downstream processing or handoff to external systems.


Variables

Name

Reference

Type

Required

Default

Options

Description

Input Folder

FOLDER_NAME

Alphanumeric

Name of the local folder on Workflows where the target file lives. If left blank, will look in the home directory.

Input Filename

FILE_NAME

Alphanumeric

Name of the target file on Platform. Can be regex if "Match Type" is set accordingly.

Remove Columns From Output

ENABLE_DROP

Boolean

True

Remove Columns from CSV Output

Columns to Drop

DROP_COLUMNS

Comma-Separated List of Columns To Remove from the Output


Script Workflow

  1. Read Configuration

    • Grabs FOLDER_NAME and FILE_NAME from environment variables.

    • Verifies that the file is a valid .json.

  2. Load JSON Input

    • Parses the .json file.

    • Supports either a single JSON object or a list of records.

  3. Drop Columns (Optional)

    • If ENABLE_DROP is "true", removes any keys listed in DROP_COLUMNS from each record.

  4. Write Output

    • Creates a .csv file in the same folder with the same base filename.

    • Writes the resulting data with headers based on the keys of the first record.

  5. Logging

    • Prints confirmation of conversion.

    • Prints dropped columns if any were removed.


Example

Given: products.json

CODE
[   {"id": "123", "name": "Shirt", "price": "29.99", "internal_notes": "New"},   {"id": "456", "name": "Hat", "price": "19.99", "internal_notes": "Old"} ] 

With:

  • ENABLE_DROP=true

  • DROP_COLUMNS=internal_notes

Output: products.csv

CODE
id,name,price 123,Shirt,29.99 456,Hat,19.99 


Alli Workflows Best Practices

  • Pair this step after a data API or transformation step that outputs JSON.

  • Use DROP_COLUMNS to sanitize or redact internal metadata.

  • Chain this step into data pipelines feeding into AI models, dashboards, or storage.


⚠️ Notes

  • The script expects well-formed JSON and will raise errors if the input is malformed.

  • Column order is determined by the keys in the first record.

  • Output file will have the same name as input but with a .csv extension.


🧾 Sample Log Output

CODE
Converted ./products.json to ./products.csv Dropped columns: ['internal_notes'] 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.