npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@runnerty/executor-json2csv

v3.0.2

Published

Runnerty module: JSON2CSV executor

Downloads

13

Readme

NPM version Downloads

Executor for Runnerty: JSON2CSV

Installation:

Through NPM

npm i @runnerty/executor-json2csv

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

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:

rty add @runnerty/executor-json2csv

Configuration sample:

Add in config.json:

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

Plan sample:

Add in plan.json:

JSON Example

[
  {
    "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:

{
  "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:

{
  "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:

{
  "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.