@@ -292,6 +292,10 @@ class Output:
292
292
"""Optional configuration for writing CSV files, to be used when the
293
293
`output_format` is OutputFormat.CSV_ARCHIVE. These configurations are
294
294
passed as kwargs to the `DictWriter` class from the `csv` module."""
295
+ json_configurations : Optional [dict [str , Any ]] = None
296
+ """Optional configuration for writing JSON files, to be used when the
297
+ `output_format` is OutputFormat.JSON. These configurations are passed as
298
+ kwargs to the `json.dumps` function."""
295
299
assets : Optional [list [Asset ]] = None
296
300
"""Optional list of assets to be included in the output."""
297
301
@@ -342,6 +346,8 @@ def to_dict(self) -> dict[str, any]:
342
346
343
347
if self .output_format == OutputFormat .CSV_ARCHIVE :
344
348
output_dict ["csv_configurations" ] = self .csv_configurations
349
+ elif self .output_format == OutputFormat .JSON :
350
+ output_dict ["json_configurations" ] = self .json_configurations
345
351
346
352
return output_dict
347
353
@@ -383,10 +389,23 @@ def _write_json(
383
389
"assets" : assets ,
384
390
}
385
391
392
+ json_configurations = {}
393
+ if hasattr (output , "json_configurations" ) and output .json_configurations is not None :
394
+ json_configurations = output .json_configurations
395
+
396
+ indent , custom_serial = 2 , _custom_serial
397
+ if "indent" in json_configurations :
398
+ indent = json_configurations ["indent" ]
399
+ del json_configurations ["indent" ]
400
+ if "default" in json_configurations :
401
+ custom_serial = json_configurations ["default" ]
402
+ del json_configurations ["default" ]
403
+
386
404
serialized = json .dumps (
387
405
final_output ,
388
- indent = 2 ,
389
- default = _custom_serial ,
406
+ indent = indent ,
407
+ default = custom_serial ,
408
+ ** json_configurations ,
390
409
)
391
410
392
411
if path is None or path == "" :
0 commit comments