Skip to content

aiskillstore/marketplace / skills/89jobrien/file-converter

file-converter

Verified

This skill handles file format conversions across documents (PDF, DOCX, Markdown, HTML, TXT), data files (JSON, CSV, YAML, XML, TOML), and images (PNG, JPG, WebP, SVG, GIF). Use when the user requests converting, transforming, or exporting files between formats. Generates conversion code dynamically based on the specific request.

FileKindSize
SKILL.mdskill md3.5 KB
references/data-conversions.mdmarkdown3.2 KB
references/document-conversions.mdmarkdown2.7 KB
references/image-conversions.mdmarkdown4.0 KB
skill-report.jsonconfig40.0 KB

references/data-conversions.md

View on GitHub
---
author: Joseph OBrien
status: unpublished
updated: '2025-12-23'
version: 1.0.1
tag: skill
type: reference
parent: file-converter
---

# Data Conversion Reference

## Type Coercion

### JSON to CSV

JSON types map to CSV strings. Handle carefully:

```python
import csv
import json

def flatten_for_csv(data):
    if isinstance(data, list) and all(isinstance(d, dict) for d in data):
        return data
    raise ValueError("CSV requires list of flat dictionaries")

with open("input.json") as f:
    data = json.load(f)

flat_data = flatten_for_csv(data)

with open("output.csv", "w", newline="") as f:
    if flat_data:
        writer = csv.DictWriter(f, fieldnames=flat_data[0].keys())
        writer.writeheader()
        writer.writerows(flat_data)
```

### CSV to JSON

All CSV values are strings. Convert types explicitly:

```python
import csv
import json

def infer_type(value):
    if value == "":
        return None
    try:
        return int(value)
    except ValueError:
        pass
    try:
        return float(value)
    except ValueError:
        pass
    if value.lower() in ("true", "false"):
        return value.lower() == "true"
    return value

with open("input.csv") as f:
    reader = csv.DictReader(f)
    data = [{k: infer_type(v) for k, v in row.items()} for row in reader]

with open("output.json", "w") as f:
    json.dump(data, f, indent=2)
```

## Nested Structures

### Flattening Nested JSON for CSV

```python
def flatten_dict(d, parent_key="", sep="_"):
    items = []
    for k, v in d.items():
        new_key = f"{parent_key}{sep}{k}" if parent_key else k
        if isinstance(v, dict):
            items.extend(flatten_dict(v, new_key, sep).items())
        elif isinstance(v, list):
            items.append((new_key, json.dumps(v)))
        else:
            items.append((new_key, v))
    return dict(items)
```

### XML Handling

**xmltodict** converts XML to OrderedDict:

```python
import xmltodict
import json

with open("input.xml") as f:
    data = xmltodict.parse(f.read())

with open("output.json", "w") as f:
    json.dump(data, f, indent=2)
```

Attributes become `@attr`, text becomes `#text`:

```xml
<item id="1">value</item>
```

Becomes:

```json
{"item": {"@id": "1", "#text": "value"}}
```

## YAML Specifics

### Multi-document YAML

```python
import yaml

with open("input.yaml") as f:
    docs = list(yaml.safe_load_all(f))
```

### Preserving Order

```python
import yaml

with open("input.yaml") as f:
    data = yaml.safe_load(f)

with open("output.yaml", "w") as f:
    yaml.dump(data, f, default_flow_style=False, sort_keys=False)
```

## TOML Handling

Python 3.11+ has `tomllib` built-in (read-only):

```python
import tomllib

with open("input.toml", "rb") as f:
    data = tomllib.load(f)
```

For writing, use `tomli-w`:

```python
import tomli_w

with open("output.toml", "wb") as f:
    tomli_w.dump(data, f)
```

## Schema Considerations

When converting between formats, preserve these semantics:

| Source | Target | Watch For |
|--------|--------|-----------|
| JSON | YAML | Dates (JSON has no date type) |
| YAML | JSON | Anchors/aliases (not supported in JSON) |
| CSV | JSON | Header row naming, empty values |
| JSON | CSV | Nested objects, arrays |
| XML | JSON | Attributes vs elements, namespaces |
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall