# widl2json

> WIDL -> JSON command line tool

Latest version **0.1.0** (published 2021-05-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install widl2json
pnpm add widl2json
yarn add widl2json
bun add widl2json
```

Provides the command `widl2json`.

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-05-20 |
| First published | 2021-05-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jsoverson |
| Maintainers | jsoverson |
| Keywords | widl, json, converter, wasm, webassembly, wapc |

## Links

- npm: https://www.npmjs.com/package/widl2json
- npm.io page: https://npm.io/package/widl2json

## Dependencies (4)

- [np](https://npm.io/package/np.md) ^7.5.0
- [yargs](https://npm.io/package/yargs.md) ^17.0.1
- [verror](https://npm.io/package/verror.md) ^1.10.0
- [@wapc/widl](https://npm.io/package/@wapc/widl.md) ^0.0.7

## 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

- 0.1.0 (latest) — 2021-05-20

## README

# widl2json

CLI tool that converts [WIDL schemas](https://github.com/wapc/widl-spec) to JSON, see also [waPC](https://wapc.io/) and the [WIDL](https://jsoverson.github.io/widl-validator/)

## Installation

```sh
$ npm install -g widl2json
```

## Usage

```sh
$ widl2json schema.widl --pretty
```

Will output:

```json
{
  "kind": "Document",
  "definitions": [
    {
      "kind": "NamespaceDefinition",
      "name": {
        "kind": "Name",
        "value": "greeting"
      },
      "annotations": []
    },
    {
      "kind": "InterfaceDefinition",
      "operations": [
        {
          "kind": "OperationDefinition",
          "name": {
            "kind": "Name",
            "value": "sayHello"
          },
          "parameters": [
            {
              "kind": "ParameterDefinition",
              "name": {
                "kind": "Name",
                "value": "name"
              },
              "type": {
                "kind": "Named",
                "name": {
                  "kind": "Name",
                  "value": "string"
                }
              },
              "annotations": []
            }
          ],
          "type": {
            "kind": "Named",
            "name": {
              "kind": "Name",
              "value": "string"
            }
          },
          "annotations": [],
          "unary": false
        }
      ],
      "annotations": []
    }
  ]
}
```

## Usage with `jq`

Print all interfaces in a schema:

```sh
$ widl2json schema.widl | jq '.definitions | map(select(.kind== "InterfaceDefinition")) | length'
```

Output a markdown-formatted list of Namespaces, their interfaces, and the interface signatures.

```sh
$ widl2json schema.widl | jq -r '.definitions[] | (select(.kind=="NamespaceDefinition")| "# Namespace `\(.name.value)`"), (select(.kind== "InterfaceDefinition") | .operations[] | "- \(.name.value)(\(.parameters[]| "\(.name.value):\(.type.name.value)")) => \(.type.name.value)") '
```

```md
# Namespace `greeting`

- sayHello(name:string) => string
```

## Options

```sh
$ widl2json --help

widl2json <file> [options]

Convert WIDL schemas to JSON

Positionals:
  file  Path to schema file                                             [string]

Options:
      --version  Show version number                                   [boolean]
  -h, --help     Show help                                             [boolean]
  -t, --terse    Omit empty arrays from the JSON      [boolean] [default: false]
  -p, --pretty   Pretty print the JSON output         [boolean] [default: false]

Examples:
  widl2json schema.widl --pretty  Outputs pretty-printed JSON
```

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