Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ricsam/jsonc-cli
Read and modify JSONC documents. A CLI front-end for the jsonc-parser npm package
https://github.com/ricsam/jsonc-cli
cli javascript json jsonc nodejs
Last synced: 10 days ago
JSON representation
Read and modify JSONC documents. A CLI front-end for the jsonc-parser npm package
- Host: GitHub
- URL: https://github.com/ricsam/jsonc-cli
- Owner: ricsam
- License: mit
- Created: 2022-11-09T14:52:42.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-28T08:08:16.000Z (almost 2 years ago)
- Last Synced: 2024-09-23T11:37:51.261Z (about 2 months ago)
- Topics: cli, javascript, json, jsonc, nodejs
- Language: JavaScript
- Homepage:
- Size: 63.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonc-cli
Read and modify JSONC documents (JSON with comments). A CLI front-end for the [jsonc-parser](https://www.npmjs.com/package/jsonc-parser) npm package.
[![npm](https://img.shields.io/npm/v/jsonc-cli)](https://www.npmjs.com/package/jsonc-cli)
[![npm](https://img.shields.io/npm/dw/jsonc-cli?label=npm%20downloads)](https://www.npmjs.com/package/jsonc-cli)
[![GitHub Repo stars](https://img.shields.io/github/stars/ricsam/jsonc-cli?style=social)](https://github.com/ricsam/jsonc-cli)## Installation
```bash
npm install -g jsonc-cli
```## Usage
```txt
jsonc [args]Commands:
jsonc modify Modify a JSONC document from stdin. Formatting options
are only applied to the injected JSON
jsonc format Format a JSONC document from stdin
jsonc read [JSONPath] Prints the JSON value at the given path in a JSONC
document from stdinOptions:
--version Show version number [boolean]
--help Show help [boolean]
```## Examples
### Print a value
```bash
echo '{"animal":"dog"}' | jsonc read '["animal"]' -r
```
will print `dog`To print without newline add `-n`
### Format document
```bash
echo '{"animal":"dog" // with some comments\n}' | jsonc format
```
will print
```jsonc
{
"animal": "dog" // with some comments
}
```
### Modify document
```bash
echo '{"animal":"dog"}' | jsonc modify -p '["animal"]' -v '"cat"'
```
will print
```json
{"animal":"cat"}
```### Write to file
```bash
echo '{"animal":"dog"}' | jsonc read '["animal"]' -r -f output.txt
cat output.txt # dog
```
### Modify a file
It is important to add the `-n` when you modify to prevent additional trailing new lines to be added
```bash
cat .vscode/settings.json | jsonc modify -n -p '["typescript.tsdk"]' -v '"app/node_modules/typescript/lib"' -f .vscode/settings.json
```