@tehw0lf/n8n-nodes-toon 1.0.1
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 +388 -0
- package/dist/nodes/Toon/Toon.node.d.ts +5 -0
- package/dist/nodes/Toon/Toon.node.js +300 -0
- package/dist/nodes/Toon/Toon.node.js.map +1 -0
- package/dist/nodes/Toon/Toon.node.json +15 -0
- package/dist/nodes/Toon/ToonDecoder.d.ts +19 -0
- package/dist/nodes/Toon/ToonDecoder.js +523 -0
- package/dist/nodes/Toon/ToonDecoder.js.map +1 -0
- package/dist/nodes/Toon/ToonEncoder.d.ts +20 -0
- package/dist/nodes/Toon/ToonEncoder.js +287 -0
- package/dist/nodes/Toon/ToonEncoder.js.map +1 -0
- package/dist/nodes/Toon/ToonUtils.d.ts +16 -0
- package/dist/nodes/Toon/ToonUtils.js +244 -0
- package/dist/nodes/Toon/ToonUtils.js.map +1 -0
- package/dist/nodes/Toon/toon.svg +4 -0
- package/dist/nodes/Toon/types.d.ts +55 -0
- package/dist/nodes/Toon/types.js +20 -0
- package/dist/nodes/Toon/types.js.map +1 -0
- package/dist/package.json +64 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 tehw0lf
|
|
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,388 @@
|
|
|
1
|
+
# n8n-nodes-toon
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/n8n-nodes-toon)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
This is an n8n community node that provides bidirectional conversion between **TOON (Token-Oriented Object Notation)** and JSON formats. TOON is a line-oriented, indentation-based format optimized for LLM prompts and structured data interchange.
|
|
7
|
+
|
|
8
|
+
[n8n](https://n8n.io/) is a [fair-code licensed](https://docs.n8n.io/sustainable-use-license/) workflow automation platform.
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [What is TOON?](#what-is-toon)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Operations](#operations)
|
|
15
|
+
- [Configuration Options](#configuration-options)
|
|
16
|
+
- [Usage Examples](#usage-examples)
|
|
17
|
+
- [Use Cases](#use-cases)
|
|
18
|
+
- [Compatibility](#compatibility)
|
|
19
|
+
- [Zero Dependencies](#zero-dependencies)
|
|
20
|
+
- [Resources](#resources)
|
|
21
|
+
|
|
22
|
+
## What is TOON?
|
|
23
|
+
|
|
24
|
+
**TOON (Token-Oriented Object Notation)** is a compact text format that encodes the JSON data model with explicit structure and minimal quoting. It's particularly efficient for arrays of uniform objects — common in data exports, API responses, and LLM prompts.
|
|
25
|
+
|
|
26
|
+
### Key Features
|
|
27
|
+
|
|
28
|
+
- **Line-oriented and indentation-based** — similar to YAML but more deterministic
|
|
29
|
+
- **Minimal quoting** — strings are quoted only when necessary
|
|
30
|
+
- **Explicit array lengths** — detect truncation and malformed data
|
|
31
|
+
- **Tabular arrays** — declare field lists once, then list values row by row
|
|
32
|
+
- **Multiple delimiters** — comma, tab, or pipe for different use cases
|
|
33
|
+
- **Zero external dependencies** — pure Node.js implementation
|
|
34
|
+
|
|
35
|
+
### Quick Example
|
|
36
|
+
|
|
37
|
+
**JSON:**
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"users": [
|
|
41
|
+
{"id": 1, "name": "Alice", "role": "admin"},
|
|
42
|
+
{"id": 2, "name": "Bob", "role": "user"}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**TOON:**
|
|
48
|
+
```
|
|
49
|
+
users[2]{id,name,role}:
|
|
50
|
+
1,Alice,admin
|
|
51
|
+
2,Bob,user
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The TOON format is **50% more compact** than JSON for tabular data, making it ideal for:
|
|
55
|
+
- **LLM prompts** — fit more context in token limits
|
|
56
|
+
- **Data serialization** — compact representation of structured data
|
|
57
|
+
- **API responses** — human-readable but machine-parseable
|
|
58
|
+
- **Configuration files** — cleaner syntax than JSON
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
Follow the [n8n community nodes installation guide](https://docs.n8n.io/integrations/community-nodes/installation/).
|
|
63
|
+
|
|
64
|
+
### npm
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install n8n-nodes-toon
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### n8n Cloud
|
|
71
|
+
|
|
72
|
+
In n8n Cloud or self-hosted n8n (v0.200+):
|
|
73
|
+
|
|
74
|
+
1. Go to **Settings** → **Community Nodes**
|
|
75
|
+
2. Select **Install**
|
|
76
|
+
3. Enter `n8n-nodes-toon` and agree to the risks
|
|
77
|
+
4. Click **Install**
|
|
78
|
+
|
|
79
|
+
The TOON node will appear in your node palette under the **Transform** category.
|
|
80
|
+
|
|
81
|
+
## Operations
|
|
82
|
+
|
|
83
|
+
The TOON node supports two operations:
|
|
84
|
+
|
|
85
|
+
### 1. JSON to TOON
|
|
86
|
+
|
|
87
|
+
Convert JSON data to TOON format.
|
|
88
|
+
|
|
89
|
+
**Input:** JSON object or array
|
|
90
|
+
**Output:** TOON formatted text
|
|
91
|
+
|
|
92
|
+
**Use case:** Prepare data for LLM prompts, compact serialization
|
|
93
|
+
|
|
94
|
+
### 2. TOON to JSON
|
|
95
|
+
|
|
96
|
+
Parse TOON formatted text back to JSON.
|
|
97
|
+
|
|
98
|
+
**Input:** TOON formatted text
|
|
99
|
+
**Output:** JSON object or array
|
|
100
|
+
|
|
101
|
+
**Use case:** Parse LLM responses, deserialize TOON data
|
|
102
|
+
|
|
103
|
+
## Configuration Options
|
|
104
|
+
|
|
105
|
+
### Encoding Options (JSON→TOON)
|
|
106
|
+
|
|
107
|
+
| Option | Type | Default | Description |
|
|
108
|
+
|--------|------|---------|-------------|
|
|
109
|
+
| **Indent Size** | Number | `2` | Spaces per indentation level |
|
|
110
|
+
| **Delimiter** | Choice | `comma` | Delimiter for array values (`comma`, `tab`, `pipe`) |
|
|
111
|
+
| **Key Folding** | Choice | `off` | Collapse single-key chains (`off`, `safe`) |
|
|
112
|
+
| **Flatten Depth** | Number | `999` | Maximum segments to fold (999 = unlimited) |
|
|
113
|
+
|
|
114
|
+
### Decoding Options (TOON→JSON)
|
|
115
|
+
|
|
116
|
+
| Option | Type | Default | Description |
|
|
117
|
+
|--------|------|---------|-------------|
|
|
118
|
+
| **Expected Indent Size** | Number | `2` | Expected indentation for validation |
|
|
119
|
+
| **Strict Mode** | Boolean | `true` | Enforce array counts and indentation |
|
|
120
|
+
| **Expand Paths** | Choice | `off` | Split dotted keys (`off`, `safe`) |
|
|
121
|
+
|
|
122
|
+
### Input/Output Configuration
|
|
123
|
+
|
|
124
|
+
| Option | Type | Default | Description |
|
|
125
|
+
|--------|------|---------|-------------|
|
|
126
|
+
| **Input Mode** | Choice | `field` | Use specific field or entire JSON |
|
|
127
|
+
| **Input Field** | String | `data` | Field containing input data |
|
|
128
|
+
| **Output Field** | String | `data` | Field name for output |
|
|
129
|
+
|
|
130
|
+
## Usage Examples
|
|
131
|
+
|
|
132
|
+
### Example 1: LLM Context Preparation
|
|
133
|
+
|
|
134
|
+
**Workflow:** Fetch Users → JSON to TOON → Send to LLM
|
|
135
|
+
|
|
136
|
+
Use TOON to fit more context into LLM token limits while maintaining readability.
|
|
137
|
+
|
|
138
|
+
**Input (JSON):**
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"users": [
|
|
142
|
+
{"id": 1, "name": "Alice", "role": "admin", "active": true},
|
|
143
|
+
{"id": 2, "name": "Bob", "role": "user", "active": true},
|
|
144
|
+
{"id": 3, "name": "Charlie", "role": "user", "active": false}
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Output (TOON - comma delimiter):**
|
|
150
|
+
```
|
|
151
|
+
users[3]{id,name,role,active}:
|
|
152
|
+
1,Alice,admin,true
|
|
153
|
+
2,Bob,user,true
|
|
154
|
+
3,Charlie,user,false
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Token Savings:** ~40-50% fewer tokens than equivalent JSON for structured data.
|
|
158
|
+
|
|
159
|
+
### Example 2: Parse LLM Structured Output
|
|
160
|
+
|
|
161
|
+
**Workflow:** Send Prompt to LLM → TOON to JSON → Process Data
|
|
162
|
+
|
|
163
|
+
LLMs can generate TOON format more reliably than JSON due to simpler syntax.
|
|
164
|
+
|
|
165
|
+
**LLM Output (TOON):**
|
|
166
|
+
```
|
|
167
|
+
result:
|
|
168
|
+
tasks[3]{name,priority,status}:
|
|
169
|
+
"Update docs",high,pending
|
|
170
|
+
"Fix bug #123",high,done
|
|
171
|
+
"Refactor code",low,pending
|
|
172
|
+
summary: "3 tasks identified"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Parsed JSON:**
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"result": {
|
|
179
|
+
"tasks": [
|
|
180
|
+
{"name": "Update docs", "priority": "high", "status": "pending"},
|
|
181
|
+
{"name": "Fix bug #123", "priority": "high", "status": "done"},
|
|
182
|
+
{"name": "Refactor code", "priority": "low", "status": "pending"}
|
|
183
|
+
],
|
|
184
|
+
"summary": "3 tasks identified"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Example 3: Working with CSV Data
|
|
190
|
+
|
|
191
|
+
n8n has excellent built-in CSV support via the "Extract from File" node. Use TOON for transformations:
|
|
192
|
+
|
|
193
|
+
**Workflow:** Read File → Extract from CSV → JSON to TOON → Transform → TOON to JSON → Use Data
|
|
194
|
+
|
|
195
|
+
1. Use n8n's "Extract from File" (CSV) node to parse CSV files
|
|
196
|
+
2. The extracted data is already JSON (one item per row)
|
|
197
|
+
3. Use "JSON to TOON" to convert to TOON format for LLM processing
|
|
198
|
+
4. Use "TOON to JSON" to convert back to JSON for further processing
|
|
199
|
+
|
|
200
|
+
### Example 4: Key Folding for Nested Data
|
|
201
|
+
|
|
202
|
+
**Workflow:** API Request → JSON to TOON (Key Folding: Safe) → Transform
|
|
203
|
+
|
|
204
|
+
Simplify deeply nested JSON structures.
|
|
205
|
+
|
|
206
|
+
**Input:**
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"user": {
|
|
210
|
+
"profile": {
|
|
211
|
+
"name": "Alice",
|
|
212
|
+
"email": "alice@example.com"
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Output (with Key Folding):**
|
|
219
|
+
```
|
|
220
|
+
user.profile.name: Alice
|
|
221
|
+
user.profile.email: alice@example.com
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Example 5: Different Delimiters
|
|
225
|
+
|
|
226
|
+
Use tab delimiters for data with commas in values.
|
|
227
|
+
|
|
228
|
+
**TOON (tab delimiter):**
|
|
229
|
+
```
|
|
230
|
+
products[2]{id name price}:
|
|
231
|
+
1 "Widget, Small" 9.99
|
|
232
|
+
2 "Gadget, Large" 19.99
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Use Cases
|
|
236
|
+
|
|
237
|
+
### 1. LLM Integration
|
|
238
|
+
|
|
239
|
+
**Problem:** JSON wastes tokens on quotes, brackets, and redundant keys.
|
|
240
|
+
|
|
241
|
+
**Solution:** TOON reduces token usage by 40-50% for structured data.
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
Workflow: Data Source → JSON to TOON → LLM → TOON to JSON → Process
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 2. API Response Transformation
|
|
248
|
+
|
|
249
|
+
**Problem:** API responses are verbose JSON that's hard to read in logs.
|
|
250
|
+
|
|
251
|
+
**Solution:** Convert to TOON for compact, human-readable logging.
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
Workflow: API Request → JSON to TOON → Log/Store → TOON to JSON → Use
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### 3. Data Format Conversion
|
|
258
|
+
|
|
259
|
+
**Problem:** Need to transform data between different formats for different systems.
|
|
260
|
+
|
|
261
|
+
**Solution:** Use TOON as an intermediate format for transformations.
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
Workflow: Extract from CSV → JSON to TOON → Transform → TOON to JSON → Send to API
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### 4. Configuration Management
|
|
268
|
+
|
|
269
|
+
**Problem:** JSON config files are verbose and don't support comments well.
|
|
270
|
+
|
|
271
|
+
**Solution:** Store configs in TOON format for better readability.
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
Workflow: Read TOON Config → TOON to JSON → Apply Settings
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### 5. Report Generation
|
|
278
|
+
|
|
279
|
+
**Problem:** Need to generate readable reports from structured data.
|
|
280
|
+
|
|
281
|
+
**Solution:** Convert to TOON for human-friendly text representation.
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
Workflow: Fetch Data → JSON to TOON → Format Report → Send Email
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Compatibility
|
|
288
|
+
|
|
289
|
+
- **n8n version:** 0.200.0 or later
|
|
290
|
+
- **Node.js:** 18.x or later
|
|
291
|
+
- **TOON Specification:** v2.0
|
|
292
|
+
|
|
293
|
+
## Advanced Features
|
|
294
|
+
|
|
295
|
+
### Strict Mode
|
|
296
|
+
|
|
297
|
+
When enabled (default), the decoder validates:
|
|
298
|
+
- Array element counts match declared length
|
|
299
|
+
- Indentation multiples match expected indent size
|
|
300
|
+
- Proper structure and syntax
|
|
301
|
+
|
|
302
|
+
Disable for lenient parsing of hand-written TOON.
|
|
303
|
+
|
|
304
|
+
### Path Expansion
|
|
305
|
+
|
|
306
|
+
Convert dotted keys into nested objects:
|
|
307
|
+
|
|
308
|
+
**TOON:**
|
|
309
|
+
```
|
|
310
|
+
user.name: Alice
|
|
311
|
+
user.email: alice@example.com
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**JSON (with expandPaths: safe):**
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"user": {
|
|
318
|
+
"name": "Alice",
|
|
319
|
+
"email": "alice@example.com"
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Round-Trip Guarantees
|
|
325
|
+
|
|
326
|
+
TOON guarantees lossless round-trip conversion:
|
|
327
|
+
|
|
328
|
+
- **JSON → TOON → JSON** preserves all data and structure
|
|
329
|
+
- Works with any valid JSON input
|
|
330
|
+
- Maintains data types (strings, numbers, booleans, null)
|
|
331
|
+
|
|
332
|
+
## Zero Dependencies
|
|
333
|
+
|
|
334
|
+
This node has **zero production dependencies**:
|
|
335
|
+
- Pure Node.js implementation
|
|
336
|
+
- No external libraries required
|
|
337
|
+
- Minimal package size
|
|
338
|
+
- No security vulnerabilities from dependencies
|
|
339
|
+
|
|
340
|
+
## Troubleshooting
|
|
341
|
+
|
|
342
|
+
### Issue: "Input must be a string" error
|
|
343
|
+
|
|
344
|
+
**Cause:** TOON to JSON operation expects string input.
|
|
345
|
+
|
|
346
|
+
**Solution:** Ensure input field contains TOON text, not a JSON object.
|
|
347
|
+
|
|
348
|
+
### Issue: Strict mode validation errors
|
|
349
|
+
|
|
350
|
+
**Cause:** TOON data doesn't match expected structure.
|
|
351
|
+
|
|
352
|
+
**Solution:** Disable strict mode or fix indentation/counts in TOON data.
|
|
353
|
+
|
|
354
|
+
### Issue: Key folding conflicts
|
|
355
|
+
|
|
356
|
+
**Cause:** Both `user.name` and `user` keys exist in same object.
|
|
357
|
+
|
|
358
|
+
**Solution:** Use `keyFolding: "safe"` which only folds when safe, or disable key folding.
|
|
359
|
+
|
|
360
|
+
### Issue: Round-trip doesn't match exactly
|
|
361
|
+
|
|
362
|
+
**Cause:** TOON normalizes data (e.g., -0 → 0, sorts object keys).
|
|
363
|
+
|
|
364
|
+
**Solution:** This is expected — TOON preserves semantic meaning, not exact formatting.
|
|
365
|
+
|
|
366
|
+
## Resources
|
|
367
|
+
|
|
368
|
+
- **TOON Specification:** See [SPEC.md](SPEC.md) in the repository for complete format details
|
|
369
|
+
- **n8n Documentation:** https://docs.n8n.io/
|
|
370
|
+
- **Community Nodes Guide:** https://docs.n8n.io/integrations/community-nodes/
|
|
371
|
+
- **GitHub Repository:** https://github.com/tehw0lf/n8n-nodes-toon
|
|
372
|
+
- **Issues & Support:** https://github.com/tehw0lf/n8n-nodes-toon/issues
|
|
373
|
+
|
|
374
|
+
## License
|
|
375
|
+
|
|
376
|
+
MIT © [tehw0lf](https://github.com/tehw0lf)
|
|
377
|
+
|
|
378
|
+
## Author
|
|
379
|
+
|
|
380
|
+
**tehw0lf** <tehwolf@protonmail.com>
|
|
381
|
+
|
|
382
|
+
## Contributing
|
|
383
|
+
|
|
384
|
+
Contributions are welcome! Please open an issue or pull request on GitHub.
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
**Note:** This node implements the TOON Specification v2.0. See `SPEC.md` for complete format documentation.
|