@traversable/schema
    Preparing search index...

    Function fromJson

    • Convert a blob of JSON data into a zod schema that represents that blob's greatest lower bound.

      Type Parameters

      • S extends
            | undefined
            | null
            | string
            | number
            | bigint
            | boolean
            | symbol
            | RegExp
            | Date
            | { -readonly [K in string
            | number
            | symbol]: Mut<S[K], RegExp | Date> }
      • T = fromJson<S>

      Parameters

      • json: S

      Returns T

      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()])) })
    • Convert a blob of JSON data into a zod schema that represents that blob's greatest lower bound.

      Parameters

      Returns ZodUnknown

      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()])) })
    Index

    Properties

    Properties

    writeable: (json: Json.Fixpoint) => string

    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()])) })