Skip to content

Add sorting keys to model_dump_json #7424

Open
pydantic/pydantic-core
#1637
@AqemiArnold

Description

@AqemiArnold

Initial Checks

  • I have searched Google & GitHub for similar requests and couldn't find anything
  • I have read and followed the docs and still think this feature is missing

Description

I may be missing something, I do apologize in advance.

From reading the docs, it appears that the .model_dump_json() method of the BaseModel does not support the sorting of the keys when serializing objects to json.
Would it be possible to add a boolean of some sort to enable recursive sorting of the keys, as follows: .model_dump_json(sort_keys=True)

Affected Components

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions