@@ -123,16 +123,19 @@ def _set_options(
123123
124124 self ._sort_keys : bool = sort_keys
125125 self ._indent_str : Optional [str ] = None if minify else indent
126- self ._key_separator : str = ": "
126+
127+ if minify :
128+ self ._key_separator : str = ':'
129+ else :
130+ self ._key_separator = ": "
127131
128132 if not indent and not minify :
129133 self ._item_separator : str = "; "
130134 else :
131135 self ._item_separator = ';'
132136
133137 if minify :
134- self ._trailing_semicolon : bool = True
135- self ._key_separator = ':'
138+ self ._trailing_semicolon = False
136139 elif trailing_semicolon is None :
137140 self ._trailing_semicolon = indent is not None
138141 else :
@@ -266,7 +269,7 @@ def _iterencode_list(
266269 if first :
267270 yield ''
268271 first = False
269- elif not self . _minify :
272+ else :
270273 yield ' '
271274
272275 if isinstance (value , (list , tuple )):
@@ -315,7 +318,9 @@ def _iterencode_dict(
315318 indent_level += 1
316319 newline_indent = '\n ' + self ._indent_str * indent_level
317320 assert newline_indent is not None
318- yield newline_indent
321+
322+ if indent_level > 0 :
323+ yield newline_indent
319324
320325 first = True
321326 if self ._sort_keys :
@@ -359,9 +364,12 @@ def _iterencode_dict(
359364 if indent_level >= 0 :
360365 if self ._indent_closing_brace :
361366 assert self ._indent_str is not None
362- yield self ._indent_str + '}'
363- else :
364- yield '}'
367+ yield self ._indent_str
368+
369+ yield '}'
370+
371+ if not self ._minify :
372+ yield '\n '
365373
366374 if self ._markers is not None and marker_id is not None :
367375 del self ._markers [marker_id ]
0 commit comments