jsontool-cli
v1.0.0
Published
Powerful JSON processing CLI: format, validate, minify, query, diff, CSV conversion. Zero dependencies.
Downloads
122
Maintainers
Readme
@mazhu/jsontool
Powerful JSON processing CLI — zero dependencies, pure Node.js
Install
npm install -g @mazhu/jsontoolCommands
| Command | Alias | Description |
|---------|-------|-------------|
| fmt | format, pretty | Format / pretty-print JSON |
| min | minify, compress | Minify JSON |
| val | validate, check | Validate JSON syntax |
| jq | query | Query with JSONPath |
| diff | compare | Compare two JSON files |
| csv2json | csv-to-json | Convert CSV to JSON |
| json2csv | json-to-csv | Convert JSON array to CSV |
Usage
Format JSON
# Format a file
jsontool fmt data.json
# Format from pipe
echo '{"a":1}' | jsontool fmt
# Custom indent
jsontool fmt data.json --indent 4
# Sort keys alphabetically
jsontool fmt data.json --sortMinify JSON
jsontool min data.json
echo '{"a": 1, "b": 2}' | jsontool minValidate JSON
jsontool val data.json
echo '{"valid": true}' | jsontool valJSONPath Query
# Access nested property
jsontool jq '$.store.book[0].title' data.json
# All array elements
jsontool jq '$.users[*].name' data.json
# Array slice
jsontool jq '$.items[0:3]' data.json
# Recursive descent (find all 'email' keys at any depth)
jsontool jq '$..email' data.jsonSupported JSONPath features:
$.key— child access$[n]— array index$[*]— all elements$[start:end]— array slice$..key— recursive descent
Diff JSON Files
# Compare two files
jsontool diff a.json b.json
# Colored output
jsontool diff a.json b.json --colorOutput shows added (+), removed (-), and changed (~) fields with paths.
CSV → JSON
# Convert CSV file
jsontool csv2json data.csv
# From pipe
cat data.csv | jsontool csv2json
# Custom delimiter
jsontool csv2json data.csv -d ";"
# No header row
jsontool csv2json data.csv --no-headerJSON → CSV
# Convert JSON array to CSV
jsontool json2csv data.json
# Skip header
jsontool json2csv data.json --no-header
# Custom delimiter
jsontool json2csv data.json -d "\t"Pipe Support
All commands support reading from stdin:
curl -s https://api.example.com/data | jsontool fmt
cat data.csv | jsontool csv2json | jsontool jq '$[0]'
cat a.json | jsontool min > a.min.jsonLibrary Usage
const jsontool = require('@mazhu/jsontool');
// Use programmatically
const { parseCSV, escapeCSV, compare } = jsontool;Features
- ✅ Zero dependencies
- ✅ Pipe / stdin support
- ✅ Colored diff output
- ✅ Smart type detection in CSV conversion
- ✅ Key sorting option
- ✅ Custom indentation
- ✅ Custom CSV delimiters
- ✅ Quoted field handling in CSV
- ✅ Lightweight and fast
License
MIT © 迈克王
