Export data in multiple formats
✓Works with OpenClaudeYou are a data export specialist. The user wants to export data from various sources into multiple formats (JSON, CSV, XML, YAML) with validation and error handling.
What to check first
- Verify you have the
papaparselibrary for CSV:npm list papaparse - Check that
js-yamlis installed for YAML support:npm list js-yaml - Confirm your data source is accessible (array, file path, or database connection)
Steps
- Install required dependencies:
npm install papaparse js-yaml xml2js - Import the DataExporter class and instantiate it with your source data
- Call the appropriate export method based on your target format (
.toJSON(),.toCSV(),.toXML(),.toYAML()) - Handle the returned Promise and check for validation errors in the
errorsproperty - Write the exported string to a file using
fs.writeFileSync()or stream it to a response object - Validate the output format by parsing it back and comparing field counts
- Log export metadata including row count, format, and file size
- Implement custom field mapping if your data structure needs transformation before export
Code
const fs = require('fs');
const Papa = require('papaparse');
const YAML = require('js-yaml');
const xml2js = require('xml2js');
class DataExporter {
constructor(data) {
this.data = Array.isArray(data) ? data : [data];
this.errors = [];
}
toJSON(pretty = true) {
try {
return pretty ? JSON.stringify(this.data, null, 2) : JSON.stringify(this.data);
} catch (error) {
this.errors.push(`JSON export failed: ${error.message}`);
return null;
}
}
toCSV() {
try {
if (this.data.length === 0) {
this.errors.push('Cannot export empty dataset to CSV');
return null;
}
return Papa.unparse(this.data, {
header: true,
dynamicTyping: false,
skipEmptyLines: true
});
} catch (error) {
this.errors.push(`CSV export failed: ${error.message}`);
return null;
}
}
toYAML() {
try {
return YAML.dump(this.data, { indent: 2, lineWidth: -1 });
} catch (error) {
this.errors.push(`YAML export failed: ${error.message}`);
return null;
}
}
async toXML(rootElement = 'root', itemElement = 'item') {
try {
const builder = new xml2js.Builder({ rootName: rootElement });
const xmlObject = { [itemElement]: this.data };
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Data & Analytics Skills
Other Claude Code skills in the same category — free to download.
CSV Parser
Parse and process CSV files
Data Transformer
Transform data between formats (JSON, XML, CSV)
Analytics Setup
Set up analytics tracking (GA4, Mixpanel, PostHog)
Data Pipeline
Create data processing pipeline
Report Generator
Generate reports from data
Chart Creator
Create charts and visualizations (Chart.js, D3)
ETL Script
Create ETL (Extract, Transform, Load) scripts
Data Validator
Validate data integrity and format
Want a Data & Analytics skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.