json-term 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +176 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +718 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +695 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +111 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +638 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +592 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 authoritydmc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# json-term ๐ณ
|
|
2
|
+
|
|
3
|
+
[](https://github.com/authoritydmc/json-term/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/json-term)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
> **High-fidelity interactive terminal JSON viewer, collapsible tree explorer, type syntax highlighter, and structural diff tool** across macOS, Linux, and Windows.
|
|
10
|
+
|
|
11
|
+
Never drown in unformatted 5,000-line JSON outputs or fight with false-positive line diffs again. `json-term` lets you interactively collapse/expand nested objects, inspect JSONPaths, copy values to your clipboard, and perform key-order independent structural diffs directly inside your terminal.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## โจ Features
|
|
16
|
+
|
|
17
|
+
- ๐ณ **Interactive Collapsible Tree**: Expand and collapse objects/arrays with `Enter`, `Space`, or arrow keys (`โถ 25 items` / `โผ`).
|
|
18
|
+
- ๐จ **Type-Aware Syntax Highlighting**: Bold cyan keys, green strings, yellow numbers, magenta booleans, and dimmed nulls.
|
|
19
|
+
- โก **Key-Aware Structural Diffing**: Ignores arbitrary key order differences and visually highlights additions (`+`), removals (`-`), and mutations (`~`).
|
|
20
|
+
- ๐ฏ **1-Key JSONPath & Value Copying**: Hit `p` to copy the node's JSONPath (`data.users[0].address.city`) or `y` to copy its formatted JSON value to the system clipboard.
|
|
21
|
+
- ๐ **Interactive Search & Filter (`/`)**: Instant fuzzy search across keys and values with automatic matched node expansion.
|
|
22
|
+
- ๐ฐ **Pipe-Friendly & CI Mode (`--print`)**: Easily pipe `curl`, `kubectl`, or `docker` logs into interactive viewer or non-interactive formatted trees.
|
|
23
|
+
- ๐ฆ **Zero Native C++ Build Dependencies**: Pure JavaScript / TypeScript running anywhere Node.js runs.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ๐ Installation
|
|
28
|
+
|
|
29
|
+
### Global CLI Tool
|
|
30
|
+
```bash
|
|
31
|
+
npm install -g json-term
|
|
32
|
+
# or run directly with npx
|
|
33
|
+
npx json-term data.json
|
|
34
|
+
# or shorthand alias
|
|
35
|
+
npx jsonx data.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### In Your Project (Library)
|
|
39
|
+
```bash
|
|
40
|
+
npm install json-term
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## ๐ ๏ธ CLI Usage & Examples
|
|
46
|
+
|
|
47
|
+
### 1. Interactive Tree Viewer
|
|
48
|
+
```bash
|
|
49
|
+
# View local JSON file
|
|
50
|
+
jsonx package.json
|
|
51
|
+
|
|
52
|
+
# View piped API response
|
|
53
|
+
curl -s https://api.github.com/repos/nodejs/node | jsonx
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 2. Structural JSON Diffing
|
|
57
|
+
```bash
|
|
58
|
+
# Compare two JSON configuration files
|
|
59
|
+
jsonx diff config.old.json config.new.json
|
|
60
|
+
|
|
61
|
+
# Diff against piped stdin
|
|
62
|
+
curl -s https://api.com/v2/config | jsonx diff config.v1.json
|
|
63
|
+
|
|
64
|
+
# Hide unchanged lines in diff
|
|
65
|
+
jsonx diff a.json b.json --no-unchanged
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Non-Interactive Pretty-Print (for scripts & CI)
|
|
69
|
+
```bash
|
|
70
|
+
# Print formatted tree to stdout
|
|
71
|
+
jsonx --print data.json
|
|
72
|
+
|
|
73
|
+
# Set initial collapse depth (e.g. depth 2)
|
|
74
|
+
jsonx data.json --depth 2 --print
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## โจ๏ธ Interactive TUI Keybindings
|
|
80
|
+
|
|
81
|
+
| Key | Action |
|
|
82
|
+
| :--- | :--- |
|
|
83
|
+
| `โ` / `k` | Move cursor up |
|
|
84
|
+
| `โ` / `j` | Move cursor down |
|
|
85
|
+
| `Enter` / `Space` / `โ` | Toggle expand / collapse node |
|
|
86
|
+
| `e` | Expand all nodes |
|
|
87
|
+
| `c` | Collapse all nodes |
|
|
88
|
+
| `p` | Copy current node's **JSONPath** to clipboard (e.g. `$.users[0].id`) |
|
|
89
|
+
| `y` / `v` | Copy current node's **JSON value** to clipboard |
|
|
90
|
+
| `/` | Interactive search / filter |
|
|
91
|
+
| `Esc` | Clear search query |
|
|
92
|
+
| `q` / `Ctrl+C` | Exit viewer |
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## ๐ Programmatic API (TypeScript & JavaScript)
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import {
|
|
100
|
+
buildTree,
|
|
101
|
+
prettyPrintTree,
|
|
102
|
+
diffJSON,
|
|
103
|
+
prettyPrintDiff,
|
|
104
|
+
calculateDiffStats,
|
|
105
|
+
InteractiveViewer
|
|
106
|
+
} from "json-term";
|
|
107
|
+
|
|
108
|
+
const data = {
|
|
109
|
+
service: "Gateway",
|
|
110
|
+
port: 8080,
|
|
111
|
+
endpoints: ["/auth", "/users", "/metrics"],
|
|
112
|
+
active: true,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// 1. Pretty Print Formatted Tree String
|
|
116
|
+
const tree = buildTree(data, "myService", "$", 0, 2);
|
|
117
|
+
console.log(prettyPrintTree(tree));
|
|
118
|
+
|
|
119
|
+
// 2. Compute Structural Diff
|
|
120
|
+
const oldConfig = { port: 8080, debug: true };
|
|
121
|
+
const newConfig = { port: 8443, debug: true, ssl: true };
|
|
122
|
+
|
|
123
|
+
const diffTree = diffJSON(oldConfig, newConfig, "configDiff");
|
|
124
|
+
const stats = calculateDiffStats(diffTree);
|
|
125
|
+
console.log(`Changes: +${stats.added} -${stats.removed} ~${stats.modified}`);
|
|
126
|
+
console.log(prettyPrintDiff(diffTree));
|
|
127
|
+
|
|
128
|
+
// 3. Launch Interactive TUI Programmatically
|
|
129
|
+
const viewer = new InteractiveViewer(tree);
|
|
130
|
+
await viewer.start();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## โ๏ธ CLI Options Reference
|
|
136
|
+
|
|
137
|
+
| Option | Shorthand | Default | Description |
|
|
138
|
+
| :--- | :--- | :--- | :--- |
|
|
139
|
+
| `--print` | `-p` | `false` | Non-interactive formatted print to stdout |
|
|
140
|
+
| `--depth <number>` | `-d` | `2` | Initial tree expansion depth |
|
|
141
|
+
| `--search <query>` | `-s` | `""` | Initial filter query for keys/values |
|
|
142
|
+
| `--no-unchanged` | | `false` | Hide unchanged nodes in diff output |
|
|
143
|
+
| `--version` | `-v` | | Output version |
|
|
144
|
+
| `--help` | `-h` | | Display help menu |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## ๐งช Development & Testing
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
git clone https://github.com/authoritydmc/json-term.git
|
|
152
|
+
cd json-term
|
|
153
|
+
npm install
|
|
154
|
+
npm test
|
|
155
|
+
npm run build
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## ๐ Automated Release & Versioning
|
|
161
|
+
|
|
162
|
+
### 1-Click from GitHub Actions
|
|
163
|
+
Go to **Actions** -> **Automated Version & Release** -> Select `patch`, `minor`, or `major` -> Click **Run workflow**.
|
|
164
|
+
|
|
165
|
+
### From Terminal
|
|
166
|
+
```bash
|
|
167
|
+
npm run release:patch
|
|
168
|
+
npm run release:minor
|
|
169
|
+
npm run release:major
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## ๐ License
|
|
175
|
+
|
|
176
|
+
[MIT](LICENSE) ยฉ 2026 authoritydmc
|
package/dist/cli.d.mts
ADDED
package/dist/cli.d.ts
ADDED