# Convert a CSV file to JSON or JSON Lines

**Use case:** 

Load a CSV from a URL and get it as a dataset you can download as JSON, Excel or XML, plus a JSON Lines file, with the columns renamed the way you want. This example converts the U.S. Treasury's daily Debt to the Penny figures. Swap in your own CSV link.

## Input

```json
{
  "fileUrl": "https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/debt_to_penny?format=csv&sort=-record_date&page[size]=10",
  "filters": [
    "exchange_rate < 1"
  ],
  "filterMode": "all",
  "dedupeBy": [
    "currency",
    "exchange_rate"
  ],
  "sortBy": [
    "exchange_rate"
  ],
  "fields": [
    "record_date -> date",
    "tot_pub_debt_out_amt -> totalDebt",
    "debt_held_public_amt -> heldByPublic",
    "intragov_hold_amt -> intragovernmental"
  ],
  "flatten": false,
  "exportFormat": "jsonl",
  "fileFormat": "auto"
}
```

## Output

```json
{
  "date": {
    "label": "Date",
    "format": "text"
  },
  "totalDebt": {
    "label": "Total debt (USD)",
    "format": "number"
  },
  "heldByPublic": {
    "label": "Held by the public",
    "format": "number"
  },
  "intragovernmental": {
    "label": "Intragovernmental",
    "format": "number"
  }
}
```

## How it works

### 1. Sign up on Apify or log in

The Dataset Transformer: Filter, Dedupe, JSON to CSV Actor is ready to run with the inputs already set for "Convert a CSV file to JSON or JSON Lines". [Sign up or log in](https://console.apify.com/create-task-from-example/6SAdgkhQNnKYvibHT) and you'll land in Apify Console with a copy of this exact task.

### 2. Start the "Convert a CSV file to JSON or JSON Lines" task

The Dataset Transformer: Filter, Dedupe, JSON to CSV Actor will start running based on the input automatically. You can also change all the input fields, like or: file url or upload (csv, json, jsonl or excel), filters, and more, to match your specific use case.

### 3. Receive the "Convert a CSV file to JSON or JSON Lines" output

Monitor the progress in real time. You will be notified as soon as your dataset is complete and ready for review. Each result includes data such as date, total debt (usd), held by the public, and more.

### 4. Integrate into your workflow

The final output is delivered in JSON, CSV, or Excel format, ready to be plugged into your workflow. You can also [run the "Convert a CSV file to JSON or JSON Lines" task via API](https://apify.com/humble-echidna/dataset-transform.md).

## About this Actor

This example demonstrates how to use [Dataset Transformer: Filter, Dedupe, JSON to CSV](https://apify.com/humble-echidna/dataset-transform.md) with a specific input configuration. Visit the [Actor detail page](https://apify.com/humble-echidna/dataset-transform.md) to learn more, explore other use cases, and run it yourself.


## How to integrate an Actor?

This Task's input is already configured above. Use it as-is rather than inventing a new one.

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 full API examples (JavaScript, Python, CLI, MCP, OpenAPI), see this Task's Actor page: https://apify.com/humble-echidna/dataset-transform.md

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`).
