config-disassembler 0.5.3

Disassemble config files into smaller files and reassemble on demand.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# Format Behavior

This document describes how `config-disassembler` handles each supported configuration format, including cross-format conversions, metadata behavior, and format-specific limitations.

---

# Supported formats

## Cross-format formats

The following formats can be freely converted between each other:

- JSON
- JSON5
- JSONC
- YAML
- TOON

Example:

```bash
# Split JSON into YAML files
config-disassembler json disassemble config.json \
  --output-format yaml

# Rebuild as JSON
config-disassembler json reassemble config \
  --output-format json
```

These conversions preserve parsed values and structure.

Format-specific syntax may not survive conversion.

Examples:

- JSONC comments are lost when rebuilding as JSON
- YAML anchors are resolved during parsing
- JSON5 trailing commas are normalized

---

# XML

XML can be split into:

- XML
- JSON
- JSON5
- YAML

…but reassembly always produces XML.

XML behavior and advanced splitting strategies are documented separately in:

- [xml.md]xml.md

---

# TOML

TOML is intentionally isolated:

- TOML ↔ TOML only

Cross-format conversions are not supported.

Example:

```text
TOML can only be converted to and from TOML; got input=json, output=toml
```

## Why TOML is isolated

TOML has structural constraints that do not map cleanly to JSON-style formats.

### No null values

TOML has no `null` equivalent.

Example:

```json
{
  "value": null
}
```

Cannot be represented in TOML without inventing custom semantics.

---

### Root must be a table

TOML documents cannot use arrays as the root value.

Valid JSON:

```json
[
  { "name": "a" },
  { "name": "b" }
]
```

Invalid TOML.

---

### Ordering constraints

TOML requires bare keys to appear before tables in the same scope.

This JSON:

```json
{
  "section": {
    "enabled": true
  },
  "name": "example"
}
```

Would need to reorder keys during TOML serialization.

Because reassembly aims to preserve deterministic structure, TOML conversions are restricted to TOML-only workflows.

---

## TOML disassembly behavior

To ensure every split file remains a valid TOML document, each shard is wrapped using its parent key.

Example:

```toml
[dependencies]
serde = "1"
tokio = "1"
```

Rather than writing a bare mapping fragment.

Arrays are similarly wrapped using TOML table-array syntax.

Example:

```toml
[[servers]]
name = "api"
```

Reassembly automatically unwraps these structures.

---

# INI

INI is also intentionally isolated:

- INI ↔ INI only

Cross-format conversions are not supported.

Example:

```text
INI can only be converted to and from INI; got input=json, output=ini
```

## Why INI is isolated

INI cannot reliably represent modern structured data formats.

Typical INI limitations include:

- values are strings
- no native arrays
- shallow nesting only
- inconsistent parser behavior across ecosystems

Example:

```ini
[settings]
enabled=true
```

This does not distinguish between:

- boolean `true`
- string `"true"`

Nested JSON-style structures also cannot be represented without inventing custom encoding rules.

---

## INI disassembly behavior

Like TOML, INI split files are wrapped using their parent section name.

Example:

```ini
[database]
host=localhost
port=5432
```

Reassembly unwraps sections automatically.

---

# Root splitting behavior

Disassembly behavior depends on the root document type.

---

## Object roots

For object-style roots:

- nested objects and arrays become separate files
- scalar values remain in `_main.<ext>`

Example input:

```json
{
  "database": {
    "host": "localhost"
  },
  "features": {
    "beta": true
  },
  "version": 1
}
```

Result:

```text
config/
├── database.json
├── features.json
├── _main.json
└── .config-disassembler.json
```

Where `_main.json` contains:

```json
{
  "version": 1
}
```

---

## Array roots

For array-style roots:

- each array item becomes its own file

By default, files use zero-padded numeric indexes.

Example:

```text
0000.json
0001.json
0002.json
```

---

## Unique IDs for arrays

Use `--unique-id <field>` to name array items using a field value.

Example:

```bash
config-disassembler json disassemble users.json \
  --unique-id id
```

Result:

```text
users/
├── 1001.json
├── 1002.json
└── 1003.json
```

This is supported for:

- JSON
- JSON5
- JSONC
- YAML
- TOON

It is not applicable to TOML or INI.

---

# Metadata sidecar

Every disassembly writes a metadata file:

```text
.config-disassembler.json
```

This stores information required for deterministic reassembly.

Typical metadata includes:

- original filename
- root type
- source format
- output format
- original key ordering
- array ordering

Example:

```json
{
  "source_format": "json",
  "output_format": "yaml",
  "root_type": "object"
}
```

Users normally do not need to edit this file manually.

Removing it may prevent correct reassembly.

---

# JSONC behavior

JSONC supports:

- comments
- trailing commas

When JSONC is:

- disassembled as JSONC
- reassembled as JSONC

…comments and trailing commas are preserved where possible.

Example:

```jsonc
{
  // API settings
  "port": 8080,
}
```

When converting JSONC into another format, only parsed values are preserved.

Comments and JSONC-specific syntax are discarded.

---

# YAML behavior

YAML parsing preserves parsed values and structure.

YAML-specific features such as:

- anchors
- aliases
- tags
- comments

may not survive cross-format conversions.

Example:

```yaml
defaults: &defaults
  enabled: true

service:
  <<: *defaults
```

Anchors are resolved during parsing and are not reconstructed during reassembly.

---

# JSON5 behavior

JSON5 supports:

- comments
- trailing commas
- unquoted keys
- single-quoted strings

Example:

```json5
{
  server: 'localhost',
}
```

These features are preserved when rebuilding as JSON5.

Cross-format conversions preserve values but normalize syntax.

---

# TOON behavior

TOON behaves similarly to JSON/YAML-style structured formats.

It supports:

- object roots
- array roots
- nested structures

Cross-format conversions are fully supported between:

- JSON
- JSON5
- JSONC
- YAML
- TOON

---

# Directory disassembly

All non-XML formats support directory input.

Example:

```bash
config-disassembler yaml disassemble envs/
```

Behavior:

- recursively walks the directory
- disassembles matching files in place
- creates sibling output directories

Example:

```text
envs/
├── dev.yaml
├── prod.yaml
├── dev/
└── prod/
```

---

# Ignore files

Directory traversal supports `.gitignore`-style filtering using `.cdignore`.

Example:

```text
**/generated/
**/secret.yaml
```

Custom paths may be supplied using:

```bash
--ignore-path custom.ignore
```

---

# Purge behavior

## `--prepurge`

Deletes existing output before writing.

Useful for:

- clean rebuilds
- CI pipelines

Example:

```bash
config-disassembler json disassemble config.json \
  --prepurge
```

---

## `--postpurge`

Deletes the input after successful completion.

Examples:

```bash
config-disassembler json disassemble config.json \
  --postpurge
```

```bash
config-disassembler json reassemble config \
  --postpurge
```

Use with care.

---

# Logging

Logging uses:

- `log`
- `env_logger`

Enable verbose output:

```bash
RUST_LOG=debug config-disassembler json disassemble config.json
```

---

# Deterministic reassembly

Reassembly preserves:

- original ordering
- root structure
- nested hierarchy
- split-file relationships

The goal is deterministic round-tripping between:

1. original source
2. disassembled representation
3. rebuilt output

Exact formatting may differ depending on the serializer used by the target format.

Examples:

- indentation
- quote style
- trailing commas
- whitespace
- comment placement

Structural equivalence is preserved even when formatting changes.