how to Deserialize Nested JSON Objects with Custom Date Format in Python using Marshmallow
I've spent hours debugging this and I'm testing a new approach and I'm experimenting with I'm refactoring my project and I'm working through a tutorial and I'm having trouble deserializing a nested JSON object into a Python class using Marshmallow, especially when it comes to custom date formats..... I have a JSON object that includes a date string in a unique format (e.g., '12-31-2023') and nested objects, but when I try to load it, I get the behavior: `ValueError: Not a valid date`. Hereβs the JSON structure Iβm working with: ```json { "user": { "id": 1, "name": "John Doe", "birthdate": "12-31-2023" }, "account": { "email": "john@example.com" } } ``` I created a Marshmallow schema like this: ```python from marshmallow import Schema, fields, ValidationError, post_load from datetime import datetime class UserSchema(Schema): id = fields.Int(required=True) name = fields.Str(required=True) birthdate = fields.Date(required=True, format='%m-%d-%Y') # Custom date format class AccountSchema(Schema): email = fields.Email(required=True) class FullUserSchema(Schema): user = fields.Nested(UserSchema) account = fields.Nested(AccountSchema) @post_load def make_user(self, data, **kwargs): return data ``` When I try to deserialize this JSON string using: ```python import json json_data = '''{ "user": { "id": 1, "name": "John Doe", "birthdate": "12-31-2023" }, "account": { "email": "john@example.com" } }''' schema = FullUserSchema() result = schema.loads(json_data) ``` I get the behavior mentioned above. Iβve verified that the JSON string is well-formed and the date format matches what I specified in the schema. Could there be a question with how I am handling the nested structure or the date format? Any insights on how to properly deserialize this JSON would be greatly appreciated. I'm working in a CentOS environment. Any advice would be much appreciated. What are your experiences with this? This is part of a larger CLI tool I'm building.