WIDL -> JSON command line tool
npm install widl2jsonCLI tool that converts WIDL schemas to JSON, see also waPC and the WIDL
``sh`
$ npm install -g widl2json
`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": []
}
]
}
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\(.name.value)
$ widl2json schema.widl | jq -r '.definitions[] | (select(.kind=="NamespaceDefinition")| "# Namespace "), (select(.kind== "InterfaceDefinition") | .operations[] | "- \(.name.value)(\(.parameters[]| "\(.name.value):\(.type.name.value)")) => \(.type.name.value)") '`
`mdgreetingNamespace
- sayHello(name:string) => string
`
`sh
$ widl2json --help
widl2json
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
``