Support for record key picklist convert to JSON Schema
Author: gabrielmarCreated Sep 16, 2026Updated Sep 16, 2026
With Zod, it's possible to use record key with enum/picklist and convert to JSON Schema
const arr = ['foo', 'bar']
import * as z from 'zod'
const zod = z.record(z.enum(arr), z.string())
console.log(JSON.stringify(z.toJSONSchema(zod)))
// {"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","propertyNames":{"type":"string","enum":["foo","bar"]},"additionalProperties":{"type":"string"},"required":["foo","bar"]}
import * as v from 'valibot'
const vali = v.record(v.picklist(arr), v.string())
console.log(JSON.stringify(toJsonSchema(vali, { target: 'draft-2020-12' })))
// throw ErrorSource: open-circle/valibot