···287287 t.need_separator <- false;
288288 t.state <- In_flow_mapping_value
289289 | In_flow_mapping_value ->
290290- write_anchor t anchor;
291291- write_tag t ~implicit:plain_implicit tag;
292292- write_scalar t ~style value;
293293- t.need_separator <- true;
294294- t.state <- In_flow_mapping_key
290290+ if t.need_separator then begin
291291+ (* We just finished a nested structure (array/mapping),
292292+ so this scalar is the next key, not a value *)
293293+ write t ", ";
294294+ write_anchor t anchor;
295295+ write_tag t ~implicit:plain_implicit tag;
296296+ write_scalar t ~style value;
297297+ write t ": ";
298298+ t.need_separator <- false;
299299+ t.state <- In_flow_mapping_value
300300+ end else begin
301301+ (* Normal value scalar *)
302302+ write_anchor t anchor;
303303+ write_tag t ~implicit:plain_implicit tag;
304304+ write_scalar t ~style value;
305305+ t.need_separator <- true;
306306+ t.state <- In_flow_mapping_key
307307+ end
295308 | _ ->
296309 if t.need_separator then write t ", ";
297310 t.need_separator <- true;