@@ -287,6 +287,7 @@ class SchemaSerializer:
287287 exclude_unset : bool = False ,
288288 exclude_defaults : bool = False ,
289289 exclude_none : bool = False ,
290+ sort_keys : bool = False ,
290291 round_trip : bool = False ,
291292 warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
292293 fallback : Callable [[Any ], Any ] | None = None ,
@@ -308,6 +309,7 @@ class SchemaSerializer:
308309 exclude_defaults: Whether to exclude fields that are equal to their default value.
309310 exclude_none: Whether to exclude fields that have a value of `None`.
310311 round_trip: Whether to enable serialization and validation round-trip support.
312+ sort_keys: Whether to sort dictionary keys at the root level.
311313 warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
312314 "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
313315 fallback: A function to call when an unknown value is encountered,
@@ -334,6 +336,7 @@ class SchemaSerializer:
334336 exclude_defaults : bool = False ,
335337 exclude_none : bool = False ,
336338 round_trip : bool = False ,
339+ sort_keys : bool = False ,
337340 warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
338341 fallback : Callable [[Any ], Any ] | None = None ,
339342 serialize_as_any : bool = False ,
@@ -353,6 +356,7 @@ class SchemaSerializer:
353356 exclude_defaults: Whether to exclude fields that are equal to their default value.
354357 exclude_none: Whether to exclude fields that have a value of `None`.
355358 round_trip: Whether to enable serialization and validation round-trip support.
359+ sort_keys: Whether to sort dictionary keys at the root level.
356360 warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
357361 "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
358362 fallback: A function to call when an unknown value is encountered,
@@ -377,6 +381,7 @@ def to_json(
377381 by_alias : bool = True ,
378382 exclude_none : bool = False ,
379383 round_trip : bool = False ,
384+ sort_keys : bool = False ,
380385 timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
381386 bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
382387 inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -398,6 +403,7 @@ def to_json(
398403 by_alias: Whether to use the alias names of fields.
399404 exclude_none: Whether to exclude fields that have a value of `None`.
400405 round_trip: Whether to enable serialization and validation round-trip support.
406+ sort_keys: Whether to sort dictionary keys at the root level.
401407 timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
402408 bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
403409 inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
@@ -453,6 +459,7 @@ def to_jsonable_python(
453459 by_alias : bool = True ,
454460 exclude_none : bool = False ,
455461 round_trip : bool = False ,
462+ sort_keys : bool = False ,
456463 timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
457464 bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
458465 inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -474,6 +481,7 @@ def to_jsonable_python(
474481 by_alias: Whether to use the alias names of fields.
475482 exclude_none: Whether to exclude fields that have a value of `None`.
476483 round_trip: Whether to enable serialization and validation round-trip support.
484+ sort_keys: Whether to sort dictionary keys at the root level.
477485 timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
478486 bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
479487 inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
0 commit comments