pydantic-yaml icon indicating copy to clipboard operation
pydantic-yaml copied to clipboard

to_yaml_str() changes order of key

Open dinjazelena opened this issue 1 year ago • 2 comments

Hey, how can i keep my order of keys same as in model? This method changes it.

dinjazelena avatar Oct 04 '23 11:10 dinjazelena

Since we currently dump to JSON (to support custom JSON dumping and preserve it in YAML), and JSON doesn't preserve key order, pydantic-yaml doesn't support model key order, I'm afraid. This is something that is definitely planned at some point, but not currently in v1. It's simple to implement for trivial cases, but supporting all that Pydantic supports would make this really tricky.

NowanIlfideme avatar Oct 04 '23 15:10 NowanIlfideme

Hey there,

Has there been any change on this front? I too would like the keys to be in the same order as the model which just makes things easier to read for the user. Problem is, as you surely know, there's no easy way to do this with json.loads.

cjshrader avatar Aug 23 '24 22:08 cjshrader