-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathjson_test.go
More file actions
1255 lines (1192 loc) · 25.3 KB
/
json_test.go
File metadata and controls
1255 lines (1192 loc) · 25.3 KB
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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package json_test
import (
"bytes"
"testing"
"github.com/speakeasy-api/openapi/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.yaml.in/yaml/v4"
)
func TestYAMLToJSON_Success(t *testing.T) {
t.Parallel()
tests := []struct {
name string
yamlInput string
expectedJSON string
indentation int
}{
{
name: "simple scalar string",
yamlInput: `hello world`,
expectedJSON: `"hello world"
`,
indentation: 2,
},
{
name: "simple scalar number",
yamlInput: `42`,
expectedJSON: `42
`,
indentation: 2,
},
{
name: "simple scalar boolean",
yamlInput: `true`,
expectedJSON: `true
`,
indentation: 2,
},
{
name: "simple object",
yamlInput: `name: John
age: 30`,
expectedJSON: `{
"name": "John",
"age": 30
}
`,
indentation: 2,
},
{
name: "nested object",
yamlInput: `person:
name: John
age: 30
address:
city: New York
zip: 10001`,
expectedJSON: `{
"person": {
"name": "John",
"age": 30,
"address": {
"city": "New York",
"zip": 10001
}
}
}
`,
indentation: 2,
},
{
name: "simple array",
yamlInput: `- apple
- banana
- cherry`,
expectedJSON: `[
"apple",
"banana",
"cherry"
]
`,
indentation: 2,
},
{
name: "array of objects",
yamlInput: `- name: John
age: 30
- name: Jane
age: 25`,
expectedJSON: `[
{
"name": "John",
"age": 30
},
{
"name": "Jane",
"age": 25
}
]
`,
indentation: 2,
},
{
name: "mixed types in object",
yamlInput: `string: hello
number: 42
boolean: true
null_value: null
array:
- 1
- 2
- 3
object:
nested: value`,
expectedJSON: `{
"string": "hello",
"number": 42,
"boolean": true,
"null_value": null,
"array": [
1,
2,
3
],
"object": {
"nested": "value"
}
}
`,
indentation: 2,
},
{
name: "preserves key order",
yamlInput: `zebra: last
apple: first
middle: second`,
expectedJSON: `{
"zebra": "last",
"apple": "first",
"middle": "second"
}
`,
indentation: 2,
},
{
name: "custom indentation - 4 spaces",
yamlInput: `name: John
age: 30`,
expectedJSON: `{
"name": "John",
"age": 30
}
`,
indentation: 4,
},
{
name: "custom indentation - 0 spaces (compact)",
yamlInput: `name: John
age: 30`,
expectedJSON: `{"name":"John","age":30}
`,
indentation: 0,
},
{
name: "empty object",
yamlInput: `{}`,
expectedJSON: `{}
`,
indentation: 2,
},
{
name: "empty array",
yamlInput: `[]`,
expectedJSON: `[]
`,
indentation: 2,
},
{
name: "numeric keys converted to strings",
yamlInput: `1: one
2: two
3: three`,
expectedJSON: `{
"1": "one",
"2": "two",
"3": "three"
}
`,
indentation: 2,
},
{
name: "yaml alias",
yamlInput: `defaults: &defaults
timeout: 30
retries: 3
production:
<<: *defaults
host: prod.example.com`,
expectedJSON: `{
"defaults": {
"timeout": 30,
"retries": 3
},
"production": {
"timeout": 30,
"retries": 3,
"host": "prod.example.com"
}
}
`,
indentation: 2,
},
{
name: "booleans",
yamlInput: `lowerCaseBool: true
mixedCaseBool: True
upperCaseBool: FALSE
`,
expectedJSON: `{
"lowerCaseBool": true,
"mixedCaseBool": true,
"upperCaseBool": false
}
`,
indentation: 2,
},
{
name: "integer with leading zeros",
yamlInput: `bankCode: 009911`,
expectedJSON: `{
"bankCode": "009911"
}
`,
indentation: 2,
},
{
name: "multiple integers with leading zeros",
yamlInput: `identifiers:
bankCode: 009911
sortCode: 001234`,
expectedJSON: `{
"identifiers": {
"bankCode": "009911",
"sortCode": "001234"
}
}
`,
indentation: 2,
},
{
name: "integers with leading zeros in array",
yamlInput: `codes: [009911, 001234, 005678]`,
expectedJSON: `{
"codes": ["009911", "001234", "005678"]
}
`,
indentation: 2,
},
{
name: "octal-like integer value",
yamlInput: `value: 0777`,
expectedJSON: `{
"value": "0777"
}
`,
indentation: 2,
},
{
name: "quoted string with leading zeros preserved",
yamlInput: `bankCode: "009911"`,
expectedJSON: `{"bankCode":"009911"}` + "\n",
indentation: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var node yaml.Node
err := yaml.Unmarshal([]byte(tt.yamlInput), &node)
require.NoError(t, err, "failed to parse YAML input")
var buffer bytes.Buffer
err = json.YAMLToJSON(&node, tt.indentation, &buffer)
require.NoError(t, err, "YAMLToJSON should not return error")
actualJSON := buffer.String()
assert.Equal(t, tt.expectedJSON, actualJSON, "JSON output should match expected")
})
}
}
func TestYAMLToJSON_Error(t *testing.T) {
t.Parallel()
tests := []struct {
name string
node *yaml.Node
wantError bool
}{
{
name: "nil node",
node: nil,
wantError: false, // nil node is handled gracefully
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var buffer bytes.Buffer
err := json.YAMLToJSON(tt.node, 2, &buffer)
if tt.wantError {
assert.Error(t, err, "expected error for invalid input")
} else {
assert.NoError(t, err, "expected no error")
}
})
}
}
func TestYAMLToJSONWithConfig_Success(t *testing.T) {
t.Parallel()
tests := []struct {
name string
yamlInput string
indent string
indentCount int
expectedJSON string
}{
{
name: "2 spaces indentation",
yamlInput: `name: John
age: 30`,
indent: " ",
indentCount: 2,
expectedJSON: `{
"name": "John",
"age": 30
}
`,
},
{
name: "4 spaces indentation",
yamlInput: `name: John
age: 30`,
indent: " ",
indentCount: 4,
expectedJSON: `{
"name": "John",
"age": 30
}
`,
},
{
name: "single tab indentation",
yamlInput: `name: John
age: 30`,
indent: "\t",
indentCount: 1,
expectedJSON: "{\n\t\"name\": \"John\",\n\t\"age\": 30\n}\n",
},
{
name: "double tab indentation",
yamlInput: `name: John
age: 30`,
indent: "\t",
indentCount: 2,
expectedJSON: "{\n\t\t\"name\": \"John\",\n\t\t\"age\": 30\n}\n",
},
{
name: "tabs with nested object",
yamlInput: `person:
name: John
age: 30
address:
city: New York`,
indent: "\t",
indentCount: 1,
expectedJSON: "{\n\t\"person\": {\n\t\t\"name\": \"John\",\n\t\t\"age\": 30,\n\t\t\"address\": {\n\t\t\t\"city\": \"New York\"\n\t\t}\n\t}\n}\n",
},
{
name: "tabs with array",
yamlInput: `items:
- apple
- banana
- cherry`,
indent: "\t",
indentCount: 1,
expectedJSON: "{\n\t\"items\": [\n\t\t\"apple\",\n\t\t\"banana\",\n\t\t\"cherry\"\n\t]\n}\n",
},
{
name: "zero indentation (compact)",
yamlInput: `name: John
age: 30`,
indent: " ",
indentCount: 0,
expectedJSON: `{"name":"John","age":30}
`,
},
{
name: "3 spaces indentation",
yamlInput: `name: John
age: 30`,
indent: " ",
indentCount: 3,
expectedJSON: `{
"name": "John",
"age": 30
}
`,
},
{
name: "tabs with array of objects",
yamlInput: `- name: John
age: 30
- name: Jane
age: 25`,
indent: "\t",
indentCount: 1,
expectedJSON: "[\n\t{\n\t\t\"name\": \"John\",\n\t\t\"age\": 30\n\t},\n\t{\n\t\t\"name\": \"Jane\",\n\t\t\"age\": 25\n\t}\n]\n",
},
{
name: "scalar string with tabs",
yamlInput: `hello world`,
indent: "\t",
indentCount: 1,
expectedJSON: "\"hello world\"\n",
},
{
name: "tabs preserving key order",
yamlInput: `zebra: last
apple: first
middle: second`,
indent: "\t",
indentCount: 1,
expectedJSON: "{\n\t\"zebra\": \"last\",\n\t\"apple\": \"first\",\n\t\"middle\": \"second\"\n}\n",
},
{
name: "empty indent string with non-zero count (compact)",
yamlInput: `name: John
age: 30`,
indent: "",
indentCount: 5,
expectedJSON: `{"name":"John","age":30}
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var node yaml.Node
err := yaml.Unmarshal([]byte(tt.yamlInput), &node)
require.NoError(t, err, "failed to parse YAML input")
var buffer bytes.Buffer
err = json.YAMLToJSONWithConfig(&node, tt.indent, tt.indentCount, true, &buffer)
require.NoError(t, err, "YAMLToJSONWithIndentation should not return error")
actualJSON := buffer.String()
assert.Equal(t, tt.expectedJSON, actualJSON, "JSON output should match expected")
})
}
}
func TestYAMLToJSON_ArrayFormats(t *testing.T) {
t.Parallel()
tests := []struct {
name string
yamlInput string
expectedJSON string
indentation int
description string
}{
{
name: "flow style array - single line compact",
yamlInput: `items: [apple, banana, cherry]`,
expectedJSON: `{
"items": ["apple", "banana", "cherry"]
}
`,
indentation: 2,
description: "Flow style arrays remain compact in JSON (preserves source formatting)",
},
{
name: "block style array - already multi-line",
yamlInput: `items:
- apple
- banana
- cherry`,
expectedJSON: `{
"items": [
"apple",
"banana",
"cherry"
]
}
`,
indentation: 2,
description: "Block style arrays remain multi-line in JSON",
},
{
name: "nested flow arrays",
yamlInput: `matrix: [[1, 2], [3, 4], [5, 6]]`,
expectedJSON: `{
"matrix": [[1, 2], [3, 4], [5, 6]]
}
`,
indentation: 2,
description: "Nested flow arrays remain compact (preserves source formatting)",
},
{
name: "mixed flow and block arrays",
yamlInput: `config:
inline: [1, 2, 3]
block:
- a
- b
- c`,
expectedJSON: `{
"config": {
"inline": [1, 2, 3],
"block": [
"a",
"b",
"c"
]
}
}
`,
indentation: 2,
description: "Mixed flow and block style arrays - flow stays compact, block expands",
},
{
name: "empty array flow style",
yamlInput: `empty: []`,
expectedJSON: `{
"empty": []
}
`,
indentation: 2,
description: "Empty flow style arrays - root expands, value stays compact",
},
{
name: "single element flow array",
yamlInput: `single: [one]`,
expectedJSON: `{
"single": ["one"]
}
`,
indentation: 2,
description: "Single element flow arrays remain compact",
},
{
name: "array of objects in flow style",
yamlInput: `users: [{name: John, age: 30}, {name: Jane, age: 25}]`,
expectedJSON: `{
"users": [{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]
}
`,
indentation: 2,
description: "Flow style array of objects remains compact",
},
{
name: "compact indentation with arrays",
yamlInput: `data: [1, 2, 3]`,
expectedJSON: `{"data":[1,2,3]}
`,
indentation: 0,
description: "Compact mode (indent=0) produces single-line arrays",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var node yaml.Node
err := yaml.Unmarshal([]byte(tt.yamlInput), &node)
require.NoError(t, err, "failed to parse YAML input")
var buffer bytes.Buffer
err = json.YAMLToJSON(&node, tt.indentation, &buffer)
require.NoError(t, err, "YAMLToJSON should not return error")
actualJSON := buffer.String()
assert.Equal(t, tt.expectedJSON, actualJSON, tt.description)
})
}
}
func TestYAMLToJSON_ObjectFormats(t *testing.T) {
t.Parallel()
tests := []struct {
name string
yamlInput string
expectedJSON string
indentation int
description string
}{
{
name: "flow style object - single line compact",
yamlInput: `person: {name: John, age: 30, city: NYC}`,
expectedJSON: `{
"person": {"name": "John", "age": 30, "city": "NYC"}
}
`,
indentation: 2,
description: "Flow style objects remain compact (preserves source formatting)",
},
{
name: "block style object - already multi-line",
yamlInput: `person:
name: John
age: 30
city: NYC`,
expectedJSON: `{
"person": {
"name": "John",
"age": 30,
"city": "NYC"
}
}
`,
indentation: 2,
description: "Block style objects remain multi-line in JSON",
},
{
name: "nested flow objects",
yamlInput: `data: {user: {name: John, email: john@example.com}, meta: {version: 1}}`,
expectedJSON: `{
"data": {"user": {"name": "John", "email": "john@example.com"}, "meta": {"version": 1}}
}
`,
indentation: 2,
description: "Nested flow objects remain compact (preserves source formatting)",
},
{
name: "mixed flow and block objects",
yamlInput: `config:
inline: {a: 1, b: 2}
block:
c: 3
d: 4`,
expectedJSON: `{
"config": {
"inline": {"a": 1, "b": 2},
"block": {
"c": 3,
"d": 4
}
}
}
`,
indentation: 2,
description: "Mixed flow and block style objects - flow stays compact, block expands",
},
{
name: "empty object flow style",
yamlInput: `empty: {}`,
expectedJSON: `{
"empty": {}
}
`,
indentation: 2,
description: "Empty flow style objects - root expands, value stays compact",
},
{
name: "single property flow object",
yamlInput: `config: {key: value}`,
expectedJSON: `{
"config": {"key": "value"}
}
`,
indentation: 2,
description: "Single property flow objects remain compact",
},
{
name: "compact indentation with objects",
yamlInput: `data: {a: 1, b: 2}`,
expectedJSON: `{"data":{"a":1,"b":2}}
`,
indentation: 0,
description: "Compact mode (indent=0) produces single-line objects",
},
{
name: "deeply nested mixed styles",
yamlInput: `root:
level1: {a: 1, b: [1, 2, 3]}
level2:
c: {x: 10, y: 20}
d:
- {id: 1}
- {id: 2}`,
expectedJSON: `{
"root": {
"level1": {"a": 1, "b": [1, 2, 3]},
"level2": {
"c": {"x": 10, "y": 20},
"d": [
{"id": 1},
{"id": 2}
]
}
}
}
`,
indentation: 2,
description: "Deeply nested mixed flow and block styles - flow stays compact",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var node yaml.Node
err := yaml.Unmarshal([]byte(tt.yamlInput), &node)
require.NoError(t, err, "failed to parse YAML input")
var buffer bytes.Buffer
err = json.YAMLToJSON(&node, tt.indentation, &buffer)
require.NoError(t, err, "YAMLToJSON should not return error")
actualJSON := buffer.String()
assert.Equal(t, tt.expectedJSON, actualJSON, tt.description)
})
}
}
func TestYAMLToJSON_ComplexMixedFormats(t *testing.T) {
t.Parallel()
tests := []struct {
name string
yamlInput string
expectedJSON string
indentation int
description string
}{
{
name: "swagger-like structure with mixed formats",
yamlInput: `swagger: "2.0"
info: {title: API, version: 1.0.0}
paths:
/users:
get:
tags: [users]
responses:
"200":
description: Success`,
expectedJSON: `{
"swagger": "2.0",
"info": {"title": "API", "version": "1.0.0"},
"paths": {
"/users": {
"get": {
"tags": ["users"],
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}
`,
indentation: 2,
description: "Real-world API spec with mixed flow/block styles",
},
{
name: "configuration file with inline arrays",
yamlInput: `server:
ports: [80, 443, 8080]
hosts: [localhost, example.com]
options: {timeout: 30, retries: 3}`,
expectedJSON: `{
"server": {
"ports": [80, 443, 8080],
"hosts": ["localhost", "example.com"],
"options": {"timeout": 30, "retries": 3}
}
}
`,
indentation: 2,
description: "Config file with inline arrays and objects",
},
{
name: "matrix data structure",
yamlInput: `matrix:
- [1, 0, 0]
- [0, 1, 0]
- [0, 0, 1]`,
expectedJSON: `{
"matrix": [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]
]
}
`,
indentation: 2,
description: "Matrix represented as array of flow arrays",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var node yaml.Node
err := yaml.Unmarshal([]byte(tt.yamlInput), &node)
require.NoError(t, err, "failed to parse YAML input")
var buffer bytes.Buffer
err = json.YAMLToJSON(&node, tt.indentation, &buffer)
require.NoError(t, err, "YAMLToJSON should not return error")
actualJSON := buffer.String()
assert.Equal(t, tt.expectedJSON, actualJSON, tt.description)
})
}
}
func TestYAMLToJSONWithConfig_Error(t *testing.T) {
t.Parallel()
tests := []struct {
name string
node *yaml.Node
indent string
indentCount int
wantError bool
}{
{
name: "nil node",
node: nil,
indent: " ",
indentCount: 2,
wantError: false, // nil node is handled gracefully
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var buffer bytes.Buffer
err := json.YAMLToJSONWithConfig(tt.node, tt.indent, tt.indentCount, true, &buffer)
if tt.wantError {
assert.Error(t, err, "expected error for invalid input")
} else {
assert.NoError(t, err, "expected no error")
}
})
}
}
func TestJSONRoundTrip_PreservesFormatting(t *testing.T) {
t.Parallel()
tests := []struct {
name string
inputJSON string
indent string
indentCount int
description string
}{
{
name: "compact single-line object",
inputJSON: `{"name":"John","age":30,"active":true}` + "\n",
indent: " ",
indentCount: 2,
description: "Compact JSON should stay compact",
},
{
name: "compact single-line array",
inputJSON: `[1,2,3,4,5]` + "\n",
indent: " ",
indentCount: 2,
description: "Compact arrays stay compact",
},
{
name: "compact nested structures",
inputJSON: `{"user":{"name":"John","address":{"city":"NYC","zip":10001}},"tags":["dev","admin"]}` + "\n",
indent: " ",
indentCount: 2,
description: "Deeply nested compact JSON stays compact",
},
{
name: "pretty 2-space indentation",
inputJSON: `{
"name": "John",
"age": 30,
"address": {
"city": "New York",
"zip": 10001
},
"tags": [
"developer",
"admin"
]
}
`,
indent: " ",
indentCount: 2,
description: "Pretty JSON with 2-space indent preserved",
},
{
name: "pretty 4-space indentation",
inputJSON: `{
"name": "John",
"age": 30,
"nested": {
"level1": {
"level2": "value"
}
}
}
`,
indent: " ",
indentCount: 4,
description: "Pretty JSON with 4-space indent preserved",
},
{
name: "tab indentation",
inputJSON: "{\n\t\"name\": \"John\",\n\t\"age\": 30,\n\t\"address\": {\n\t\t\"city\": \"NYC\"\n\t}\n}\n",
indent: "\t",
indentCount: 1,
description: "Tab-indented JSON preserved",
},
{
name: "mixed formatting - compact and pretty",
inputJSON: `{
"compact": {"a": 1, "b": 2},
"pretty": {
"c": 3,
"d": 4
},
"array": [1, 2, 3],
"prettyArray": [
"one",
"two"
]
}
`,
indent: " ",
indentCount: 2,
description: "Mixed compact and pretty formatting preserved",
},
{
name: "array of compact objects",
inputJSON: `[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"},
{"id": 3, "name": "Charlie"}
]
`,
indent: " ",
indentCount: 2,
description: "Array of compact objects in pretty array",
},
{
name: "compact array of pretty objects",
inputJSON: `[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]` + "\n",
indent: " ",
indentCount: 2,
description: "Compact root with inline objects",
},
{
name: "empty structures",
inputJSON: `{
"emptyObject": {},
"emptyArray": [],
"nestedEmpty": {
"obj": {},
"arr": []
}
}
`,
indent: " ",
indentCount: 2,
description: "Empty objects and arrays preserved",
},
{
name: "all JSON data types",