npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hoangvu12/yomi

v1.0.0

Published

Yomi (読み) - Flexible JSON parser that interprets LLM output to match Zod schemas

Readme

Yomi (読み)

Yomi (pronounced "yoh-mee", 読み) means "reading" or "interpretation" in Japanese. This library interprets messy LLM output and coerces it to match your Zod schemas.

Version Compatibility

| Yomi Version | Zod Version | Notes | |--------------|-------------|-------| | 1.x | ^4.0.0 | Zod v4 support with new instanceof-based type checking | | 0.x | ^3.20.0 | Zod v3 support (legacy) |

The Problem

LLMs don't return perfect JSON. They return:

{name: "John", age: "25",}  // unquoted keys, trailing comma
Here's the user data: {"name": "John", "age": 25}  // wrapped in text
{"name": "John", "age": "25", "active": "yes"}  // wrong types everywhere

JSON.parse() fails. Even if it succeeds, your types are wrong.

The Solution

Yomi uses a two-phase approach inspired by BAML's schema-aligned parsing:

  1. Flexible JSON parsing - Fix malformed JSON, extract from markdown/text
  2. Schema-aligned coercion - Walk your Zod schema and coerce values to match
import { z } from "zod";
import { parse } from "@hoangvu12/yomi";

const User = z.object({
  name: z.string(),
  age: z.number(),
  active: z.boolean(),
});

const result = parse(User, `{name: "John", age: "25", active: "yes"}`);

// result.success === true
// result.data.value === { name: "John", age: 25, active: true }
// result.data.flags === ["json_repaired", "string_to_number", "string_to_bool"]

Installation

npm install @hoangvu12/yomi zod
# or
bun add @hoangvu12/yomi zod

API

parse(schema, input)

Parse and coerce input to match schema. Returns a result object.

const result = parse(UserSchema, rawInput);

if (result.success) {
  console.log(result.data.value); // typed as z.infer<typeof UserSchema>
  console.log(result.data.flags); // what transformations happened
} else {
  console.log(result.error); // what went wrong
}

parseOrThrow(schema, input)

Same as parse, but throws on failure. Returns the coerced value directly.

const user = parseOrThrow(UserSchema, rawInput);
// user is typed as z.infer<typeof UserSchema>

coerce(schema, value) / coerceOrThrow(schema, value)

Skip JSON parsing, just do schema coercion on an already-parsed value.

const result = coerce(UserSchema, { name: "John", age: "25" });

What It Fixes

JSON Parsing

| Input | Fixed | |-------|-------| | {name: "John"} | Unquoted keys | | {"name": "John",} | Trailing commas | | // comment | Comments | | 'single quotes' | Single quotes | | ```json {...}``` | Markdown code blocks | | Here's the data: {...} | Surrounding text |

Type Coercion

| From | To | Example | |------|----|---------| | "123" | number | "25"25 | | "12.5" | int | "12.5"13 (rounded) | | 123 | string | 123"123" | | "true", "yes", "1" | boolean | → true | | "false", "no", "0" | boolean | → false | | value | array | "x"["x"] | | [value] | single | ["x"]"x" | | "PENDING" | enum | Case-insensitive match | | null | undefined | For optional fields | | {extra: ...} | object | Extra keys ignored |

Flags

Every transformation is tracked. Use flags to:

  • Log when coercion happens in production
  • Detect if defaults were used vs explicit values
  • Debug why parsing succeeded unexpectedly
const result = parse(Schema, input);
if (result.success) {
  for (const flag of result.data.flags) {
    console.log(flag);
    // { flag: "string_to_number" }
    // { flag: "extra_keys_ignored", keys: ["confidence"] }
    // { flag: "float_to_int", original: 12.5, rounded: 13 }
  }
}

Available Flags

| Flag | Meaning | |------|---------| | json_repaired | jsonrepair fixed the JSON | | extracted_from_markdown | Extracted from ```json ``` block | | extracted_from_text | Extracted JSON from surrounding text | | string_to_number | "123"123 | | string_to_bool | "true"true | | number_to_string | 123"123" | | bool_to_string | true"true" | | float_to_int | 12.513 | | single_to_array | x[x] | | array_to_single | [x]x | | null_to_undefined | nullundefined | | extra_keys_ignored | Object had extra properties | | missing_optional_key | Optional field was missing | | default_used | Used schema's default value | | enum_case_insensitive | "PENDING" matched "pending" |

Supported Zod Types

  • Primitives: string, number, boolean, null, undefined, literal
  • Objects: object, record
  • Arrays: array, tuple
  • Unions: union, discriminatedUnion, optional, nullable
  • Enums: enum, nativeEnum
  • Modifiers: default, catch
  • Passthrough: any, unknown

How It Works

LLM Output (string)
       │
       ▼
┌─────────────────┐
│  Flexible JSON  │  ← jsonrepair + markdown extraction
│     Parser      │
└────────┬────────┘
         │ unknown
         ▼
┌─────────────────┐
│  Schema-Aligned │  ← walks Zod schema tree
│    Coercer      │
└────────┬────────┘
         │ { value: T, flags: Flag[] }
         ▼
     Result<T>

The coercer recursively walks your Zod schema using instanceof checks (Zod v4) to identify schema types, dispatching to type-specific coercion functions. Each coercer tries to interpret the input value as the expected type, recording flags when transformations occur.

License

MIT