@@ -305,6 +305,7 @@ class SchemaSerializer:
305305 exclude_unset : bool = False ,
306306 exclude_defaults : bool = False ,
307307 exclude_none : bool = False ,
308+ sort_keys : bool = False ,
308309 round_trip : bool = False ,
309310 warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
310311 fallback : Callable [[Any ], Any ] | None = None ,
@@ -326,6 +327,7 @@ class SchemaSerializer:
326327 exclude_defaults: Whether to exclude fields that are equal to their default value.
327328 exclude_none: Whether to exclude fields that have a value of `None`.
328329 round_trip: Whether to enable serialization and validation round-trip support.
330+ sort_keys: Whether to sort dictionary keys at the root level.
329331 warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
330332 "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
331333 fallback: A function to call when an unknown value is encountered,
@@ -352,6 +354,7 @@ class SchemaSerializer:
352354 exclude_defaults : bool = False ,
353355 exclude_none : bool = False ,
354356 round_trip : bool = False ,
357+ sort_keys : bool = False ,
355358 warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
356359 fallback : Callable [[Any ], Any ] | None = None ,
357360 serialize_as_any : bool = False ,
@@ -371,6 +374,7 @@ class SchemaSerializer:
371374 exclude_defaults: Whether to exclude fields that are equal to their default value.
372375 exclude_none: Whether to exclude fields that have a value of `None`.
373376 round_trip: Whether to enable serialization and validation round-trip support.
377+ sort_keys: Whether to sort dictionary keys at the root level.
374378 warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
375379 "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
376380 fallback: A function to call when an unknown value is encountered,
@@ -395,6 +399,7 @@ def to_json(
395399 by_alias : bool | None = None ,
396400 exclude_none : bool = False ,
397401 round_trip : bool = False ,
402+ sort_keys : bool = False ,
398403 timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
399404 bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
400405 inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -416,6 +421,7 @@ def to_json(
416421 by_alias: Whether to use the alias names of fields.
417422 exclude_none: Whether to exclude fields that have a value of `None`.
418423 round_trip: Whether to enable serialization and validation round-trip support.
424+ sort_keys: Whether to sort dictionary keys at the root level.
419425 timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
420426 bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
421427 inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
@@ -471,6 +477,7 @@ def to_jsonable_python(
471477 by_alias : bool | None = None ,
472478 exclude_none : bool = False ,
473479 round_trip : bool = False ,
480+ sort_keys : bool = False ,
474481 timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
475482 bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
476483 inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -492,6 +499,7 @@ def to_jsonable_python(
492499 by_alias: Whether to use the alias names of fields.
493500 exclude_none: Whether to exclude fields that have a value of `None`.
494501 round_trip: Whether to enable serialization and validation round-trip support.
502+ sort_keys: Whether to sort dictionary keys at the root level.
495503 timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
496504 bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
497505 inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
0 commit comments