# @toolia/json-args

> parse command line arguments as json

Latest version **1.1.1** (published 2019-12-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install @toolia/json-args
pnpm add @toolia/json-args
yarn add @toolia/json-args
bun add @toolia/json-args
```

Provides the command `json-args`.

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-12-01 |
| First published | 2019-12-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | George Campbell |
| Maintainers | georgecampbell |
| Keywords | arguments, command-line, tool |

## Links

- npm: https://www.npmjs.com/package/@toolia/json-args
- Repository: https://github.com/GCDeveloper/cli
- Homepage: https://github.com/GCDeveloper/cli#readme
- Issues: https://github.com/GCDeveloper/cli/issues
- npm.io page: https://npm.io/package/@toolia/json-args

## Dependencies (1)

- [esm](https://npm.io/package/esm.md) ^3.2.25

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2019-12-01
- 1.0.6 — 2019-12-01
- 1.0.5 — 2019-12-01
- 1.0.4 — 2019-12-01
- 1.0.2 — 2019-12-01
- 1.0.1 — 2019-12-01
- 1.0.0 — 2019-12-01

## README

# json-args

`npm i @toolia/json-args`

Use `-g` flag if you need to install it as a command line tool.

Process arguments passed to your node script as JSON.

It can be used as either a command line tool, or in a module.

### As a command line tool

`json-args --category=tool`

will output a json string: `{"category":"tool"}`

Another example:

`json-args --category=tool --description="process command line arguments"`

will output:

`{"category":"tool","description":"process command line arguments"}`

> You can specify either a .json file or raw JSON string as the first argument which will be parsed as the default json.

### As a module

```
// myScript.js
const jsonArgs = require("@toolia/json-args").default;

console.log(JSON.stringify(jsonArgs(process.argv.slice(2))));
```

When the above script is called e.g. `node myScript --hello`,
it would output
`{"hello":true}`

---

Provide default JSON in the second argument to the jsonArgs function:

```
// myScript.js
console.log(
  JSON.stringify(jsonArgs(process.argv.slice(2), { hello: "fizz", foo: "bar" }))
);
// input: node myScript.js hello=world
// output: {"hello":"world","foo":"bar"}
```

---

Provide options in the third argument to jsonArgs. These include:

- verbose (default false)

  - This outputs additional logs to the console.

- onlyDoubleDash (default false)

  - This ignores all arguments which do not start with `--`

---

- Arguments do not need to be specified with `--`.

- It will attempt to parse argument values as JSON (object, boolean, number etc.), else it defaults to a string.

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