msgspec
msgspec copied to clipboard
Encode field name
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`