agentleFS
agentsdanceagentsdance/agentskills/skills/data-transformer/SKILL.md

data-transformer

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Transform and reshape data between formats. Use when the user needs to convert JSON, CSV, XML, or transform data structures.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Data Transformer

Convert and reshape data between different formats.

JSON Transformations

Flatten Nested Objects

function flatten(obj, prefix = '') {
  return Object.keys(obj).reduce((acc, key) => {
    const newKey = prefix ? `${prefix}.${key}` : key;
    if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
      Object.assign(acc, flatten(obj[key], newKey));
    } else {
      acc[newKey] = obj[key];
    }
    return acc;
  }, {});
}

// Input: { user: { name: "John", address: { city: "NYC" } } }
// Output: { "user.name": "John", "user.address.city": "NYC" }

Group By

function groupBy(array, key) {
  return array.reduce((groups, item) => {
    const group = item[key];
    groups[group] = groups[group] || [];
    groups[group].push(item);
    return groups;
  }, {});
}

// Input: [{ type: "A", val: 1 }, { type: "B", val: 2 }, { type: "A", val: 3 }]
// Output: { A: [{ type: "A", val: 1 }, { type: "A", val: 3 }], B: [{ type: "B", val: 2 }] }

CSV to JSON

function csvToJson(csv) {
  const lines = csv.trim().split('\n');
  const headers = lines[0].split(',').map(h => h.trim());

  return lines.slice(1).map(line => {
    const values = line.split(',');
    return headers.reduce((obj, header, i) => {
      obj[header] = values[i]?.trim();
      return obj;
    }, {});
  });
}

JSON to CSV

function jsonToCsv(data) {
  const headers = Object.keys(data[0]);
  const rows = data.map(obj =>
    headers.map(h => JSON.stringify(obj[h] ?? '')).join(',')
  );
  return [headers.join(','), ...rows].join('\n');
}

Python (pandas)

import pandas as pd
import json

# CSV to JSON
df = pd.read_csv('data.csv')
df.to_json('data.json', orient='records')

# JSON to CSV
df = pd.read_json('data.json')
df.to_csv('data.csv', index=False)

# Excel to CSV
df = pd.read_excel('data.xlsx')
df.to_csv('data.csv', index=False)

# Pivot table
pivot = df.pivot_table(
    values='sales',
    index='product',
    columns='month',
    aggfunc='sum'
)

jq Command Line

# Extract field
cat data.json | jq '.users[].name'

# Filter
cat data.json | jq '.users | map(select(.age > 30))'

# Transform
cat data.json | jq '.users | map({name, email})'

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.