@@ -305,6 +305,7 @@ class SchemaSerializer:
305
305
exclude_unset : bool = False ,
306
306
exclude_defaults : bool = False ,
307
307
exclude_none : bool = False ,
308
+ sort_keys : bool = False ,
308
309
round_trip : bool = False ,
309
310
warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
310
311
fallback : Callable [[Any ], Any ] | None = None ,
@@ -326,6 +327,7 @@ class SchemaSerializer:
326
327
exclude_defaults: Whether to exclude fields that are equal to their default value.
327
328
exclude_none: Whether to exclude fields that have a value of `None`.
328
329
round_trip: Whether to enable serialization and validation round-trip support.
330
+ sort_keys: Whether to sort dictionary keys at the root level.
329
331
warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
330
332
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
331
333
fallback: A function to call when an unknown value is encountered,
@@ -352,6 +354,7 @@ class SchemaSerializer:
352
354
exclude_defaults : bool = False ,
353
355
exclude_none : bool = False ,
354
356
round_trip : bool = False ,
357
+ sort_keys : bool = False ,
355
358
warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
356
359
fallback : Callable [[Any ], Any ] | None = None ,
357
360
serialize_as_any : bool = False ,
@@ -371,6 +374,7 @@ class SchemaSerializer:
371
374
exclude_defaults: Whether to exclude fields that are equal to their default value.
372
375
exclude_none: Whether to exclude fields that have a value of `None`.
373
376
round_trip: Whether to enable serialization and validation round-trip support.
377
+ sort_keys: Whether to sort dictionary keys at the root level.
374
378
warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
375
379
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
376
380
fallback: A function to call when an unknown value is encountered,
@@ -395,6 +399,7 @@ def to_json(
395
399
by_alias : bool | None = None ,
396
400
exclude_none : bool = False ,
397
401
round_trip : bool = False ,
402
+ sort_keys : bool = False ,
398
403
timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
399
404
bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
400
405
inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -416,6 +421,7 @@ def to_json(
416
421
by_alias: Whether to use the alias names of fields.
417
422
exclude_none: Whether to exclude fields that have a value of `None`.
418
423
round_trip: Whether to enable serialization and validation round-trip support.
424
+ sort_keys: Whether to sort dictionary keys at the root level.
419
425
timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
420
426
bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
421
427
inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
@@ -471,6 +477,7 @@ def to_jsonable_python(
471
477
by_alias : bool | None = None ,
472
478
exclude_none : bool = False ,
473
479
round_trip : bool = False ,
480
+ sort_keys : bool = False ,
474
481
timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
475
482
bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
476
483
inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -492,6 +499,7 @@ def to_jsonable_python(
492
499
by_alias: Whether to use the alias names of fields.
493
500
exclude_none: Whether to exclude fields that have a value of `None`.
494
501
round_trip: Whether to enable serialization and validation round-trip support.
502
+ sort_keys: Whether to sort dictionary keys at the root level.
495
503
timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
496
504
bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
497
505
inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
0 commit comments