This directory contains JSON schemas for messages used in the Nostr protocol.
| Schema | Description | NIP |
|---|---|---|
event.json |
Basic structure of a Nostr event | NIP-01 |
| Schema | Description | NIP |
|---|---|---|
client-event.json |
EVENT message (publishing events) | NIP-01 |
client-req.json |
REQ message (requesting events and subscriptions) | NIP-01, NIP-50 |
client-close.json |
CLOSE message (stopping subscriptions) | NIP-01 |
| Schema | Description | NIP |
|---|---|---|
relay-event.json |
EVENT message (delivering events) | NIP-01 |
relay-ok.json |
OK message (acceptance/rejection of EVENT) | NIP-01 |
relay-eose.json |
EOSE message (end of stored events) | NIP-01 |
relay-closed.json |
CLOSED message (subscription ended) | NIP-01 |
relay-notice.json |
NOTICE message (notifications) | NIP-01 |
| Schema | Description | NIP |
|---|---|---|
kind-0.json |
User metadata (profile information) | NIP-01, NIP-05 |
Node.js:
npm install ajvPython:
pip install jsonschemaThese schemas conform to JSON Schema Draft 7. See the Usage section below for complete validation examples.
These schemas conform to JSON Schema Draft 7.
const Ajv = require('ajv');
const ajv = new Ajv();
const eventSchema = require('./event.json');
const validate = ajv.compile(eventSchema);
const event = {
id: "a".repeat(64),
pubkey: "b".repeat(64),
created_at: 1234567890,
kind: 1,
tags: [],
content: "Hello Nostr!",
sig: "c".repeat(128)
};
const valid = validate(event);
if (!valid) {
console.log(validate.errors);
}import jsonschema
import json
with open('event.json') as f:
schema = json.load(f)
event = {
"id": "a" * 64,
"pubkey": "b" * 64,
"created_at": 1234567890,
"kind": 1,
"tags": [],
"content": "Hello Nostr!",
"sig": "c" * 128
}
try:
jsonschema.validate(event, schema)
print("Valid!")
except jsonschema.ValidationError as e:
print(f"Invalid: {e}")Execute :LspSettingsLocalEdit and add the following configuration to associate schemas with specific file patterns. This enables validation and completion for Nostr-related JSON files.
{
"json-languageserver": {
"disabled": false,
"workspace_config": {
"json": {
"format": true,
"schemas": [
{
"name": "Nostr Event JSON",
"description": "Nostr Event JSON",
"fileMatch": ["**/nostr-event.json"],
"url": "https://mattn.github.io/nostr-json-schemas/event.json"
},
{
"name": "Nostr Kind 0 JSON",
"description": "Nostr Kind 0 JSON",
"fileMatch": ["**/kind0.json"],
"url": "https://mattn.github.io/nostr-json-schemas/kind-0.json"
}
// Add more schemas as needed, e.g.:
// {
// "name": "Nostr Client REQ",
// "fileMatch": ["**/client-req.json"],
// "url": "https://mattn.github.io/nostr-json-schemas/client-req.json"
// }
]
}
}
}
}VS Code has built-in support for JSON Schema validation and IntelliSense.
Add the following to your User or Workspace settings.json (accessible via File > Preferences > Settings or Ctrl+,, then search for "json schemas"):
{
"json.schemas": [
{
"fileMatch": ["**/nostr-event.json"],
"url": "https://mattn.github.io/nostr-json-schemas/event.json"
},
{
"fileMatch": ["**/kind0.json"],
"url": "https://mattn.github.io/nostr-json-schemas/kind-0.json"
}
// Add more as needed
]
}Alternatively, in individual JSON files, add a $schema property at the top level:
{
"$schema": "https://mattn.github.io/nostr-json-schemas/event.json",
// ... your event data
}You can validate JSON against these schemas using online tools:
Use the examples in the Usage section above to validate events programmatically.
All schemas conform to JSON Schema Draft 7 and can be validated using standard JSON Schema validators.
MIT
Yasuhiro Matsumoto (a.k.a. mattn)