https://github.com/dbushell/jsonlike
🍋🟩 Just enough JavaScript object validation
https://github.com/dbushell/jsonlike
bun deno javascript json nodejs typescript
Last synced: 11 months ago
JSON representation
🍋🟩 Just enough JavaScript object validation
- Host: GitHub
- URL: https://github.com/dbushell/jsonlike
- Owner: dbushell
- License: mit
- Created: 2024-07-22T12:17:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-25T06:39:10.000Z (over 1 year ago)
- Last Synced: 2025-04-10T23:13:58.418Z (11 months ago)
- Topics: bun, deno, javascript, json, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 13.7 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🍋🟩 jsonlike
[](https://jsr.io/@dbushell/jsonlike) [](https://www.npmjs.com/package/@dbushell/jsonlike)
Just enough JavaScript object validation.
**jsonlike** is a tiny < 1kB library used to validate JavaScript objects against a JSON-like schema.
It can:
* Match properties by primitive types
* Match arrays of single type values
* Match nested objects
## Usage
```ts
import {jsonlike} from '@dbushell/jsonlike';
const json = JSON.parse(`{
"greeting": "Hello, World!",
"items": [{"id": 1}, {"id": 2}, {"id": 3}]
}`);
const valid = jsonlike(json, {
greeting: 'string',
items: [{id: 'number'}]
});
```
## Notes
Use [Ajv](https://github.com/ajv-validator/ajv) or [Zod](https://github.com/colinhacks/zod) for full schema validation.
* * *
[MIT License](/LICENSE) | Copyright © 2024 [David Bushell](https://dbushell.com)