Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dbushell/jsonlike
🍋🟩 Just enough JavaScript object validation
https://github.com/dbushell/jsonlike
bun deno javascript json nodejs typescript
Last synced: 2 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 (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-28T11:17:40.000Z (4 months ago)
- Last Synced: 2024-09-29T18:41:03.445Z (3 months ago)
- Topics: bun, deno, javascript, json, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🍋🟩 jsonlike
Just enough JavaScript object validation.
[![JSR](https://jsr.io/badges/@dbushell/jsonlike?labelColor=98e6c8&color=333)](https://jsr.io/@dbushell/jsonlike) [![NPM](https://img.shields.io/npm/v/@dbushell/jsonlike?labelColor=98e6c8&color=333)](https://www.npmjs.com/package/@dbushell/jsonlike)
**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) for full schema validation.
* * *
[MIT License](/LICENSE) | Copyright © 2024 [David Bushell](https://dbushell.com)