@@ -287,6 +287,7 @@ class SchemaSerializer:
287
287
exclude_unset : bool = False ,
288
288
exclude_defaults : bool = False ,
289
289
exclude_none : bool = False ,
290
+ sort_keys : bool = False ,
290
291
round_trip : bool = False ,
291
292
warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
292
293
fallback : Callable [[Any ], Any ] | None = None ,
@@ -308,6 +309,7 @@ class SchemaSerializer:
308
309
exclude_defaults: Whether to exclude fields that are equal to their default value.
309
310
exclude_none: Whether to exclude fields that have a value of `None`.
310
311
round_trip: Whether to enable serialization and validation round-trip support.
312
+ sort_keys: Whether to sort dictionary keys at the root level.
311
313
warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
312
314
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
313
315
fallback: A function to call when an unknown value is encountered,
@@ -334,6 +336,7 @@ class SchemaSerializer:
334
336
exclude_defaults : bool = False ,
335
337
exclude_none : bool = False ,
336
338
round_trip : bool = False ,
339
+ sort_keys : bool = False ,
337
340
warnings : bool | Literal ['none' , 'warn' , 'error' ] = True ,
338
341
fallback : Callable [[Any ], Any ] | None = None ,
339
342
serialize_as_any : bool = False ,
@@ -353,6 +356,7 @@ class SchemaSerializer:
353
356
exclude_defaults: Whether to exclude fields that are equal to their default value.
354
357
exclude_none: Whether to exclude fields that have a value of `None`.
355
358
round_trip: Whether to enable serialization and validation round-trip support.
359
+ sort_keys: Whether to sort dictionary keys at the root level.
356
360
warnings: How to handle invalid fields. False/"none" ignores them, True/"warn" logs errors,
357
361
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
358
362
fallback: A function to call when an unknown value is encountered,
@@ -377,6 +381,7 @@ def to_json(
377
381
by_alias : bool = True ,
378
382
exclude_none : bool = False ,
379
383
round_trip : bool = False ,
384
+ sort_keys : bool = False ,
380
385
timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
381
386
bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
382
387
inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -398,6 +403,7 @@ def to_json(
398
403
by_alias: Whether to use the alias names of fields.
399
404
exclude_none: Whether to exclude fields that have a value of `None`.
400
405
round_trip: Whether to enable serialization and validation round-trip support.
406
+ sort_keys: Whether to sort dictionary keys at the root level.
401
407
timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
402
408
bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
403
409
inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
@@ -453,6 +459,7 @@ def to_jsonable_python(
453
459
by_alias : bool = True ,
454
460
exclude_none : bool = False ,
455
461
round_trip : bool = False ,
462
+ sort_keys : bool = False ,
456
463
timedelta_mode : Literal ['iso8601' , 'float' ] = 'iso8601' ,
457
464
bytes_mode : Literal ['utf8' , 'base64' , 'hex' ] = 'utf8' ,
458
465
inf_nan_mode : Literal ['null' , 'constants' , 'strings' ] = 'constants' ,
@@ -474,6 +481,7 @@ def to_jsonable_python(
474
481
by_alias: Whether to use the alias names of fields.
475
482
exclude_none: Whether to exclude fields that have a value of `None`.
476
483
round_trip: Whether to enable serialization and validation round-trip support.
484
+ sort_keys: Whether to sort dictionary keys at the root level.
477
485
timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
478
486
bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
479
487
inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
0 commit comments