# Data Format and Unit Converter (`brightwater-tools/data-format-unit-converter`) Actor

Offline conversion between CSV, JSON, JSON Lines, YAML, XML and TOML, plus exact unit conversion for length, mass, temperature, pressure, energy, force, power and volume. No network access and no scraping.

- **URL**: https://apify.com/brightwater-tools/data-format-unit-converter.md
- **Developed by:** [Brightwater Tools](https://apify.com/brightwater-tools) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 successful conversions

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Data Format and Unit Converter

Convert data between **CSV, JSON, JSON Lines, YAML, XML and TOML**, and convert numbers between **engineering units** with exact arithmetic. Paste your data, pick the formats, get the result. It runs fully offline: no web requests, no scraping, and your data never leaves the run.

**$0.01 per successful conversion.** Failed runs are not charged.

### What you can do with it

- Turn a **CSV export into JSON** for an API, or JSON from an API into a **CSV for Excel or Google Sheets**.
- Convert **YAML config to JSON or TOML** (and back) when moving between tools.
- Flatten nested JSON into **dotted CSV columns** (`address.city`, `tags.0`).
- Read **XML** into JSON, with attributes kept as `@name` keys.
- Convert a list of measurements between units, for example **inches to centimetres, psi to kPa, °F to °C, lbf to N, US gallons to litres**.
- Use it as a step in your **Apify integrations, Make, Zapier or n8n** workflows, or call it from the **Apify API**.

### How to use it

1. Choose a **mode**: `convert` for data formats or `units` for unit conversion.
2. Fill in the fields for that mode (see below).
3. Click **Start**. The result appears in the **Output** tab and the dataset.

#### Mode: convert

| Field | What to enter |
|---|---|
| `data` | The text to convert (paste it in) |
| `input_format` | `csv`, `json`, `jsonl`, `yaml`, `xml` or `toml` |
| `output_format` | Any of the same six |
| `csv_delimiter` | Optional, default `,` (use `;` or a tab for European CSV) |
| `xml_root` | Optional root element name when writing XML (default `root`) |
| `pretty` | Indented output for JSON, YAML and XML (default on) |

Example input:

```json
{
  "mode": "convert",
  "input_format": "json",
  "output_format": "csv",
  "data": "[{\"material\": \"steel\", \"density_kg_m3\": 7850}, {\"material\": \"aluminium\", \"density_kg_m3\": 2700}]"
}
```

Output (one dataset item):

```json
{
  "input_format": "json",
  "output_format": "csv",
  "content": "material,density_kg_m3\nsteel,7850\naluminium,2700\n"
}
```

#### Mode: units

| Field | What to enter |
|---|---|
| `units_category` | `length`, `mass`, `temperature`, `pressure`, `energy`, `force`, `power` or `volume` |
| `units_from`, `units_to` | Unit names in lower case with underscores, for example `inch`, `centimeter`, `psi`, `kilopascal`, `pound_force`, `us_gallon` |
| `values` | One number per line, up to 1,000 values |
| `precision` | Significant digits in the result (default 12) |

Supported unit names:

| Category | Units |
|---|---|
| length | `nanometer`, `micrometer`, `millimeter`, `centimeter`, `meter`, `kilometer`, `inch`, `foot`, `us_survey_foot`, `yard`, `mile`, `nautical_mile` |
| mass | `milligram`, `gram`, `kilogram`, `tonne`, `ounce`, `pound`, `stone`, `short_ton`, `long_ton` |
| temperature | `kelvin`, `celsius`, `fahrenheit`, `rankine` |
| pressure | `pascal`, `kilopascal`, `megapascal`, `bar`, `psi`, `standard_atmosphere`, `torr` |
| energy | `joule`, `kilojoule`, `kilowatt_hour`, `thermochemical_calorie`, `kilocalorie`, `btu_it`, `electronvolt` |
| force | `newton`, `kilonewton`, `dyne`, `kilogram_force`, `pound_force`, `kip` |
| power | `watt`, `kilowatt`, `megawatt`, `horsepower`, `metric_horsepower`, `btu_it_per_hour` |
| volume | `milliliter`, `liter`, `cubic_centimeter`, `cubic_meter`, `cubic_inch`, `cubic_foot`, `us_fluid_ounce`, `us_cup`, `us_pint`, `us_quart`, `us_gallon`, `imperial_gallon` |

You get one dataset item per value. Factors are exact, taken from the SI and NIST SP 811 definitions (for example 1 in = 2.54 cm exactly, 1 lb = 0.45359237 kg exactly), and rounding happens only at the end.

### Pricing

- **$0.01 per successful run** (event `conversion`). In units mode, one run with up to 1,000 values is still one conversion.
- A tiny Apify start fee per run ($0.00005).
- **Failed runs** (bad input, unsupported format) are **not charged** for the conversion.
- Apify's free plan includes monthly credit, so you can try it at no cost.

### Good to know

- **Size limit:** inputs up to 1 MB by default (`max_input_bytes`, up to 5 MB).
- **CSV has no types:** numbers and true/false come back as text after a CSV round trip.
- **Nested data in CSV** is flattened to dotted columns. Converting that CSV back does not rebuild the nesting.
- **Spreadsheet safety:** values starting with `=`, `+`, `-` or `@` are written as they are. Spreadsheets may treat them as formulas, so check untrusted data before opening it in Excel.
- **XML:** attributes become `@name` keys and mixed text becomes `#text`. XML with DOCTYPE or ENTITY declarations is refused for safety.
- **TOML** needs an object at the top level and cannot hold null values.
- **YAML** files with several documents become a list.

### FAQ

**Does it send my data anywhere?** No. The conversion runs inside your Apify run with no network calls.

**Which units are supported?** Common SI, imperial and US customary units in the eight categories above. If a unit name is not recognised, the run fails with a message listing the valid names, and you are not charged for the conversion.

**Can I call it from code?** Yes, through the Apify API or the Apify client for JavaScript or Python, like any Apify actor.

**I found a bug or need a format.** Open an issue on this actor's Issues tab.

***

Made by Brightwater Tools. Built and tested with the help of AI coding tools; every conversion rule is covered by automated tests.

# Actor input Schema

## `mode` (type: `string`):

'convert' changes the text in 'data' from one data format to another. 'units' converts each number in 'values' from one unit to another.

## `data` (type: `string`):

Text to convert (convert mode only). Paste the whole document here. Nothing is fetched from a URL or read from a file. The size limit is max_input_bytes.

## `input_format` (type: `string`):

Format of the text in 'data'. CSV must have a header row. JSON Lines holds one JSON value per line. XML with DOCTYPE or ENTITY declarations is refused.

## `output_format` (type: `string`):

Format to write. TOML needs an object at the top level. Nested data is flattened into dotted column names when written to CSV.

## `csv_delimiter` (type: `string`):

One character that separates CSV fields, for example ',' or ';' or a tab.

## `xml_root` (type: `string`):

Name of the outer element when writing XML. Use letters, digits, '\_', '-' or '.', and do not start with a digit.

## `pretty` (type: `boolean`):

Indent JSON, YAML and XML output so it is easy to read. Turn off for the smallest output.

## `max_input_bytes` (type: `integer`):

Inputs larger than this are refused with an error. The hard ceiling is 5,000,000 bytes.

## `units_category` (type: `string`):

Kind of quantity to convert. Used in 'units' mode only.

## `units_from` (type: `string`):

Source unit name, in lower case with underscores, for example 'inch', 'pound_force' or 'fahrenheit'. Used in 'units' mode only.

## `units_to` (type: `string`):

Target unit name, in lower case with underscores, for example 'centimeter' or 'celsius'. Used in 'units' mode only.

## `values` (type: `string`):

One number per line, in plain decimal notation such as 12.5 or -40. Up to 1,000 lines. Used in 'units' mode only.

## `precision` (type: `integer`):

How many significant digits to keep in each result. The arithmetic is exact; only the final output is rounded.

## Actor input object example

```json
{
  "mode": "convert",
  "data": "[{\"material\": \"steel\", \"density_kg_m3\": 7850}, {\"material\": \"aluminium\", \"density_kg_m3\": 2700}]",
  "input_format": "json",
  "output_format": "csv",
  "csv_delimiter": ",",
  "xml_root": "root",
  "pretty": true,
  "max_input_bytes": 1000000,
  "units_category": "length",
  "units_from": "inch",
  "units_to": "centimeter",
  "values": "1\n2.5\n12",
  "precision": 12
}
```

# Actor output Schema

## `results` (type: `string`):

One item per run: the converted content (data mode) or the converted values (units mode).

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("brightwater-tools/data-format-unit-converter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("brightwater-tools/data-format-unit-converter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call brightwater-tools/data-format-unit-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,brightwater-tools/data-format-unit-converter"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/9E7shq5ivBNdkAXlb/builds/pUPfxBgsbsa5P4nbU/openapi.json
