/** * @module validators/json * @description JSON validator that parses JSON strings from environment * variables, with optional Zod schema validation of the parsed value. */ import { z } from "zod/v4"; import type { JsonOptions, UndefinedDefault } from "../types.cjs"; /** * JSON validator with optional schema validation. * Parses JSON strings and optionally validates against a Zod schema. * * @param options - Validation options including optional schema * @returns Zod schema for parsed JSON with metadata * * @example * Basic JSON parsing * ```ts * const env = zenv({ * CONFIG: json({ default: { enabled: true } }) * }); * ``` * * @example * JSON with schema validation * ```ts * const configSchema = z.object({ * apiKey: z.string(), * timeout: z.number(), * features: z.array(z.string()) * }); * * const env = zenv({ * APP_CONFIG: json({ * schema: configSchema, * default: { * apiKey: 'default-key', * timeout: 5000, * features: [] * } * }) * }); * ``` * * @example * Complex nested JSON * ```ts * const env = zenv({ * FEATURE_FLAGS: json>({ * default: {}, * example: '{"feature1": true, "feature2": false}' * }) * }); * ``` * * @example * Optional json with undefined default * ```ts * const env = zenv({ * // Optional in all environments * CONFIG_JSON: json({ default: undefined }), * // Optional in dev/test, required in production * SETTINGS_JSON: json({ * devDefault: undefined, * testDefault: undefined * }) * }); * // Type: CONFIG_JSON is T | undefined * // Type: SETTINGS_JSON is T | undefined in dev/test, T in production * ``` */ export declare function json>(options: JsonOptions & ({ default: undefined; } | { devDefault: undefined; } | { testDefault: undefined; })): z.ZodType & UndefinedDefault; export declare function json>(options?: JsonOptions): z.ZodType;