# @runnerty/executor-json2csv

> Runnerty module: JSON2CSV executor

Latest version **3.0.2** (published 2023-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @runnerty/executor-json2csv
pnpm add @runnerty/executor-json2csv
yarn add @runnerty/executor-json2csv
bun add @runnerty/executor-json2csv
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2023-09-26 |
| First published | 2020-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Runnerty Tech |
| Maintainers | coderty |
| Keywords | runnerty, executor, json2csv, json, csv |

## Links

- npm: https://www.npmjs.com/package/@runnerty/executor-json2csv
- Repository: https://github.com/runnerty/executor-json2csv
- Homepage: https://github.com/runnerty/executor-json2csv#readme
- Issues: https://github.com/runnerty/executor-json2csv/issues
- npm.io page: https://npm.io/package/@runnerty/executor-json2csv

## Dependencies (5)

- [@json2csv/node](https://npm.io/package/@json2csv/node.md) ^7.0.3
- [string-to-stream](https://npm.io/package/string-to-stream.md) ~3.0.1
- [@json2csv/plainjs](https://npm.io/package/@json2csv/plainjs.md) ^7.0.3
- [@json2csv/transforms](https://npm.io/package/@json2csv/transforms.md) ^7.0.3
- [@runnerty/module-core](https://npm.io/package/@runnerty/module-core.md) ~3.1.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.0.2 (latest) — 2023-09-26
- 3.0.1 — 2022-04-26
- 3.0.0 — 2021-03-26
- 2.0.1 — 2020-10-31
- 2.0.0 — 2020-05-31

## README

<p align="center">
  <a href="http://runnerty.io">
    <img height="257" src="https://runnerty.io/assets/header/logo-stroked.png">
  </a>
  <p align="center">Smart Processes Management</p>
</p>

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url]
<a href="#badge">
<img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg">
</a>

# Executor for [Runnerty]: JSON2CSV

### Installation:

Through NPM

```bash
npm i @runnerty/executor-json2csv
```

You can also add modules to your project with [runnerty-cli]

```bash
npx runnerty-cli add @runnerty/executor-json2csv
```

This command installs the module in your project, adds example configuration in your `config.json` and creates an example plan of use.

If you have installed [runnerty-cli] globally you can include the module with this command:

```bash
rty add @runnerty/executor-json2csv
```

### Configuration sample:

Add in [config.json]:

```json
{
  "id": "json2csv_default",
  "type": "@runnerty-executor-json2csv"
}
```

### Plan sample:

Add in [plan.json]:

#### JSON Example

```json
[
  {
    "planet": "Earth",
    "radius": 6371,
    "satellites": [
      {
        "name": "moon",
        "radius": 1737
      }
    ]
  },
  {
    "planet": "Mars",
    "radius": 3389,
    "satellites": [
      {
        "name": "phobos",
        "radius": 11267
      },
      {
        "name": "deimos",
        "radius": 6.2
      }
    ]
  }
]
```

#### Example 1:

```json
{
  "id": "json2csv_default",
  "inputPath": "./planets.json",
  "outputPath": "./planets.csv"
}
```

##### CSV Output

```
"planet","radius","satellites"
"Earth",6371,"[{""name"":""moon"",""radius"":1737}]"
"Mars",3389,"[{""name"":""phobos"",""radius"":11267},{""name"":""deimos"",""radius"":6.2}]"
```

#### Example 2:

```json
{
  "id": "json2csv_default",
  "inputPath": "./planets.json",
  "outputPath": "./planets.csv",
  "options": {
    "fields": ["planet", "radius", "satellites.name", "satellites.radius"]
  },
  "transforms": {
    "unwind": { "paths": ["satellites"] }
  }
}
```

##### CSV Ouput

```
"planet","radius","satellites.name","satellites.radius"
"Earth",6371,"moon",1737
"Mars",3389,"phobos",11267
"Mars",3389,"deimos",6.2
```

#### Full params example:

```json
{
  "id": "json2csv_default",
  "inputPath": "./input.json",
  "input": "@GV(MY_JSON)",
  "outputPath": "./output.csv",
  "options": {
    "fields": ["field1", "field2", "field3"],
    "defaultValue": "NULL",
    "header": true,
    "escapedQuote": "",
    "delimiter": ";",
    "eol": "\r\n",
    "excelStrings": true,
    "includeEmptyRows": true,
    "withBOM": true
  },
  "transforms": {
    "unwind": { "paths": ["items", "items.items"], "blankOut": true },
    "flatten": { "objects": true, "arrays": true, "separator": "_" }
  }
}
```

### Params

#### Options

| Option           | Description                                                                               |
| ---------------- | ----------------------------------------------------------------------------------------- |
| fields           | List of fields to process. Defaults to field auto-detection.                              |
| defaultValue     | Default value to use for missing fields.                                                  |
| quote            | Character(s) to use as quote mark. Defaults to '"'.                                       |
| delimiter        | Character(s) to use as delimiter. Defaults to ','. (default: ",")                         |
| escapedQuote     | Character(s) to use as a escaped quote. Defaults to a double `quote`, '""'.               |
| eol              | Character(s) to use as End-of-Line for separating rows. Defaults to '\n'. (default: "\n") |
| excelStrings     | Wraps string data to force Excel to interpret it as string even if it contains a number.  |
| header           | Boolean to Enable/Disable the column name header. (Enabled by defaults)                   |
| includeEmptyRows | Boolean to Includes empty rows in the resulting CSV output.                               |
| withBOM          | Boolean to Includes BOM character at the beginning of the CSV.                            |

#### Transforms

| Option      | Description                                                                              |
| ----------- | ---------------------------------------------------------------------------------------- |
| unwind      | Creates multiple rows from a single JSON document similar to MongoDB unwind.             |
| - paths     | Unwind fields path.                                                                      |
| - blankOut  | When unwinding, blank out instead of repeating data. Defaults to false. (default: false) |
| flatten     | Nested javascript objects into a single level object.                                    |
| - object    | Flatten nested objects. Defaults to false. (default: false)                              |
| - arrays    | Flatten nested arrays. Defaults to false. (default: false)                               |
| - separator | Flattened keys separator. Defaults to '.'. (default: ".")                                |

### More information:

This executor is a wrapper of the module json2csv (zemirco), for more information consult the website of the [json2csv].

[runnerty]: http://www.runnerty.io
[downloads-image]: https://img.shields.io/npm/dm/@runnerty/executor-json2csv.svg
[npm-url]: https://www.npmjs.com/package/@runnerty/executor-json2csv
[npm-image]: https://img.shields.io/npm/v/@runnerty/executor-json2csv.svg
[david-badge]: https://david-dm.org/runnerty/executor-json2csv.svg
[david-badge-url]: https://david-dm.org/runnerty/executor-json2csv
[config.json]: http://docs.runnerty.io/config/
[plan.json]: http://docs.runnerty.io/plan/
[ejs]: https://ejs.co
[runnerty-cli]: https://www.npmjs.com/package/runnerty-cli
[json2csv]: https://github.com/zemirco/json2csv

---
_Source: https://npm.io/package/@runnerty/executor-json2csv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
