@@ -292,6 +292,10 @@ class Output:
292292 """Optional configuration for writing CSV files, to be used when the
293293 `output_format` is OutputFormat.CSV_ARCHIVE. These configurations are
294294 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."""
295299 assets : Optional [list [Asset ]] = None
296300 """Optional list of assets to be included in the output."""
297301
@@ -342,6 +346,8 @@ def to_dict(self) -> dict[str, any]:
342346
343347 if self .output_format == OutputFormat .CSV_ARCHIVE :
344348 output_dict ["csv_configurations" ] = self .csv_configurations
349+ elif self .output_format == OutputFormat .JSON :
350+ output_dict ["json_configurations" ] = self .json_configurations
345351
346352 return output_dict
347353
@@ -383,10 +389,23 @@ def _write_json(
383389 "assets" : assets ,
384390 }
385391
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+
386404 serialized = json .dumps (
387405 final_output ,
388- indent = 2 ,
389- default = _custom_serial ,
406+ indent = indent ,
407+ default = custom_serial ,
408+ ** json_configurations ,
390409 )
391410
392411 if path is None or path == "" :
0 commit comments