Typha is a lightweight TypeScript/JavaScript library for parsing JSON strings into typed objects using schemas.
It ensures that your data respects the type definitions you specify, handling numbers, booleans, strings, dates, arrays, and nested objects automatically.
- โ Parse JSON strings safely into typed objects
- โ
Supports primitives:
string,number,boolean,Date - โ Handles arrays and nested objects
- โ TypeScript ready with full type definitions
- โ Lightweight and zero dependencies
npm install typhaimport { parseWithSchema } from "typha";
// Define your schema
const schema = {
name: String,
age: Number,
active: Boolean,
createdAt: Date,
tags: [String],
profile: {
bio: String,
score: Number
}
};
// Example JSON string
const raw = JSON.stringify({
name: "raulmaciasdev",
age: "40",
active: "true",
createdAt: "2025-08-21T10:30:00.000Z",
tags: ["js", "ts"],
profile: { bio: "Dev", score: "99" }
});
// Parse using Typha
const obj = parseWithSchema(raw, schema);
console.log(obj);
/*
{
name: "raulmaciasdev",
age: 40,
active: true,
createdAt: 2025-08-21T10:30:00.000Z,
tags: ["js","ts"],
profile: { bio: "Dev", score: 99 }
}
*/Typha is open source! Feel free to fork, open issues, or submit pull requests.
MIT