msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Encode field name

Open edpyt opened this issue 3 months ago • 0 comments

Question

Hello! How to use struct field name instead of field object name? case:

import msgspec

class MyStruct(msgspec.Struct):
    my_f: str = msgspec.field(default="", name="struct_f")

encoded = msgspec.yaml.encode(msgspec.convert({"struct_f": "Hello"}, type=MyStruct))
print(encoded)  # uses `struct_f` instead of `my_f`

edpyt avatar May 21 '24 02:05 edpyt