Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How do i write zod schema for a deeply nested object

$
0
0

I have the following data:

{"2022-06-01": {"09:00am": {"time_table_id": 1,"job_id": 4,"start_working_time": "09:00am","end_working_time": "09:00pm","work_duration": "12:00:00","merchant_name": "Brands Outlet @ The Starling","address2": "Jalan SS 21/37, Damansara Utama","job_name": "Pro hero","job_application_status": "Hired"    }  }}

and this is my schema but it is giving me a zod error.

const apiScheme = z.object({  Date: z.object({    Time: z.object({      date: z.string(),      time_table_id: z.number().nullable(),      job_id: z.number(),      start_working_time: z.string(),      end_working_time: z.string(),      // work_duration: z.string(),      // merchant_name: z.string(),      // address2: z.string(),      job_name: z.string(),      job_application_status: z.string(),    }),  }),});// -- snip -- (React code):const data = useMemo(() => {  if (responseData) {    const parseData = apiScheme.parse(responseData);    //    error here ~~~~~~~~~~-^    if (parseData) {      return parseData;    }  }  return null;}, [responseData]);

Viewing all articles
Browse latest Browse all 6287

Trending Articles