import { zx } from '@traversable/zod'
let ex_01 = zx.fromJson({ abc: 'ABC', def: [] })
// ^? let ex_01: z.ZodObject<{ abc: z.ZodString, def: z.ZodArray<z.ZodUnknown> }>
console.log(zx.toString(ex_01))
// => z.object({ abc: z.string(), def: z.array(z.unknown()) })
let ex_02 = zx.fromJson({ abc: false, def: [123] })
// ^? let ex_02: z.ZodObject<{ abc: z.ZodBoolean, def: z.ZodArray<z.ZodNumber> }>
console.log(zx.toString(ex_02))
// => z.object({ abc: z.boolean(), def: z.array(z.number()) })
let ex_03 = zx.fromJson({ abc: 123, def: ['ABC', null] })
// ^? let ex_02: z.ZodObject<{ abc: z.ZodNumber, def: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNull]>> }>
console.log(zx.toString(ex_03))
// => z.object({ abc: z.number(), def: z.array(z.union([z.string(), z.null()])) })
zx.fromJson
Convert a blob of JSON data into a zod schema that represents that blob's greatest lower bound.
import { zx } from '@traversable/zod'
let ex_01 = zx.fromJson({ abc: 'ABC', def: [] })
// ^? let ex_01: z.ZodObject<{ abc: z.ZodString, def: z.ZodArray<z.ZodUnknown> }>
console.log(zx.toString(ex_01))
// => z.object({ abc: z.string(), def: z.array(z.unknown()) })
let ex_02 = zx.fromJson({ abc: false, def: [123] })
// ^? let ex_02: z.ZodObject<{ abc: z.ZodBoolean, def: z.ZodArray<z.ZodNumber> }>
console.log(zx.toString(ex_02))
// => z.object({ abc: z.boolean(), def: z.array(z.number()) })
let ex_03 = zx.fromJson({ abc: 123, def: ['ABC', null] })
// ^? let ex_02: z.ZodObject<{ abc: z.ZodNumber, def: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNull]>> }>
console.log(zx.toString(ex_03))
// => z.object({ abc: z.number(), def: z.array(z.union([z.string(), z.null()])) })
zx.fromJson.writeable
Convert a blob of JSON data into a stringified zod schema that represents that blob's greatest lower bound.
import { zx } from '@traversable/zod'
let ex_01 = zx.fromJson.writeable({ abc: 'ABC', def: [] })
console.log(ex_01)
// => z.object({ abc: z.string(), def: z.array(z.unknown()) })
let ex_02 = zx.fromJson.writeable({ abc: false, def: [123] })
console.log(ex_02)
// => z.object({ abc: z.boolean(), def: z.array(z.number()), })
let ex_03 = zx.fromJson.writeable({ abc: 123, def: ['ABC', null] })
console.log(ex_03)
// => z.object({ abc: z.number(), def: z.array(z.union([z.string(), z.null()])) })
zx.fromJson
Convert a blob of JSON data into a zod schema that represents that blob's greatest lower bound.