📋JSON Schema Converter: Genera Schemi di Validazione Automaticamente
Converti JSON in JSON Schema con un click. Rileva automaticamente tipi e formati, genera schemi Draft 2020-12 o Draft 07, e documenta le tue API in modo professionale.
JSON Schema Converter: Genera Schemi di Validazione Automaticamente
La documentazione e validazione delle API è fondamentale, ma creare JSON Schema manualmente è tedioso e soggetto a errori. Oggi presentiamo il nostro JSON Schema Converter 📋 - uno strumento che genera automaticamente JSON Schema dai tuoi dati JSON.
Cos'è JSON Schema?
JSON Schema è lo standard de facto per descrivere e validare strutture JSON. È usato in:
- OpenAPI/Swagger - Documentazione API REST
- API Gateway - Validazione richieste/risposte
- Form Generation - Generazione automatica di UI
- Data Validation - Librerie come Ajv, JSON Schema Validator
- IDE Autocomplete - IntelliSense e code completion
Esempio Pratico
JSON di input:
{
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"active": true
}
JSON Schema generato:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer" },
"active": { "type": "boolean" }
},
"additionalProperties": false
}
Nota come il converter ha:
"format": "email"integer da numberadditionalProperties: false per maggiore sicurezzaFeature Principali
🎯 Auto-Detection Intelligente
Il converter analizza i tuoi dati e rileva automaticamente:
Tipi Primitivi
Tipi Complessi
📧 Format Detection
Quando abilitato, il converter rileva automaticamente formati comuni:
| Formato | Esempio | Uso |
|---------|---------|-----|
| email | user@example.com | Validazione email |
| uri | https://example.com | URL/URI |
| uuid | 550e8400-e29b-41d4-a716-446655440000 | Identificatori univoci |
| date-time | 2025-11-17T15:30:00Z | Timestamp ISO 8601 |
| date | 2025-11-17 | Solo data |
| time | 15:30:00 | Solo ora |
| ipv4 | 192.168.1.1 | Indirizzo IPv4 |
| ipv6 | 2001:0db8::1 | Indirizzo IPv6 |
Esempio con format detection:
{
"user": {
"email": "admin@example.com",
"website": "https://example.com",
"id": "550e8400-e29b-41d4-a716-446655440000",
"created": "2025-11-17T15:30:00Z",
"ip": "192.168.1.1"
}
}
Schema generato:
{
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"email": { "type": "string", "format": "email" },
"website": { "type": "string", "format": "uri" },
"id": { "type": "string", "format": "uuid" },
"created": { "type": "string", "format": "date-time" },
"ip": { "type": "string", "format": "ipv4" }
}
}
}
}
⚙️ Opzioni Configurabili
Schema Title
Dai un nome al tuo schema per migliore documentazione:{
"$schema": "...",
"title": "User Profile Schema",
"type": "object",
...
}
Make All Fields Required
Rendi tutti i campi obbligatori automaticamente:{
"type": "object",
"properties": { ... },
"required": ["name", "email", "age"]
}
I campi null vengono esclusi dalla lista required.
Schema Version
Scegli tra:🔄 Supporto Nested Objects
Gestione completa di strutture complesse:
{
"user": {
"profile": {
"name": "John",
"contacts": {
"email": "john@example.com",
"phone": "+1234567890"
}
},
"permissions": ["read", "write"],
"metadata": {
"created": "2025-11-17T10:00:00Z",
"updated": "2025-11-17T15:30:00Z"
}
}
}
Il converter genera correttamente tutti i livelli di nesting con i rispettivi schemi.
📦 Array Support
Inferenza automatica del tipo degli elementi:
{
"tags": ["typescript", "react", "vite"],
"scores": [95, 87, 92],
"users": [
{ "name": "Alice", "age": 30 },
{ "name": "Bob", "age": 25 }
]
}
Schema generato:
{
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": { "type": "string" }
},
"scores": {
"type": "array",
"items": { "type": "integer" }
},
"users": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
}
}
}
}
}
Casi d'Uso Reali
1. Documentazione API con OpenAPI
Genera rapidamente schemi per le tue specifiche OpenAPI:
openapi: 3.0.0
paths:
/users:
post:
requestBody:
content:
application/json:
schema:
# Incolla qui lo schema generato
type: object
properties:
name:
type: string
email:
type: string
format: email
2. Validazione con Ajv
Usa lo schema per validare dati in runtime:
import Ajv from 'ajv'
import addFormats from 'ajv-formats'const ajv = new Ajv()
addFormats(ajv)
const schema = {
// Schema generato dal converter
}
const validate = ajv.compile(schema)
const data = { name: "John", email: "john@example.com" }
if (validate(data)) {
console.log('✅ Dati validi')
} else {
console.log('❌ Errori:', validate.errors)
}
3. Form Generation
Librerie come react-jsonschema-form possono generare form automaticamente:
import Form from '@rjsf/core'const schema = {
// Schema generato
}
function MyForm() {
return (
4. TypeScript Interface Generation
Usa tool come json-schema-to-typescript per generare types:
npm install -g json-schema-to-typescriptGenera TypeScript types dallo schema
json-schema-to-typescript schema.json > types.ts
Output:
export interface UserProfile {
name: string
email: string
age: number
active: boolean
}
5. Database Schema Design
Usa JSON Schema come base per definire strutture database (MongoDB, PostgreSQL JSONB, ecc.):
// MongoDB Schema Validation
db.createCollection("users", {
validator: {
$jsonSchema: {
// Schema generato dal converter
}
}
})
Workflow Consigliato
1. Prototipazione Rapida
Dati di esempio → JSON Schema Converter → Schema base → Refinement manuale
1. Crea un esempio rappresentativo dei tuoi dati 2. Genera lo schema con il converter 3. Aggiungi constraints aggiuntivi (min/max, pattern, enum, ecc.)
2. API-First Development
Request/Response examples → Schema → OpenAPI Spec → Code Generation
1. Definisci esempi di richieste/risposte 2. Genera schemi per ciascuno 3. Integra in OpenAPI specification 4. Genera client/server code
3. Documentation-Driven
JSON data → Schema → Auto-generated docs → Published API docs
Usa tool come Redoc o Swagger UI per pubblicare documentazione generata dagli schemi.
Best Practices
1. Usa Dati Rappresentativi
Fornisci un esempio completo con tutti i campi possibili:
// ❌ Incompleto
{
"name": "John"
}// ✅ Completo
{
"name": "John",
"email": "john@example.com",
"age": 30,
"active": true,
"roles": ["user", "admin"],
"metadata": {
"created": "2025-11-17T10:00:00Z"
}
}
2. Controlla i Formati Rilevati
Verifica sempre che i format rilevati siano corretti:
3. Aggiungi Constraints Manualmente
Lo schema generato è una base. Aggiungi:
minLength / maxLength per stringheminimum / maximum per numeripattern per regex validationenum per valori predefiniti{
"type": "string",
"format": "email",
"minLength": 5,
"maxLength": 100,
"pattern": "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$"
}
4. Versiona i Tuoi Schemi
Aggiungi versioning quando cambi gli schemi:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/user-profile/v2.json",
"title": "User Profile Schema",
"version": "2.0.0",
...
}
5. Usa additionalProperties
Il converter imposta additionalProperties: false per sicurezza. Valuta se:
false per validazione stricttrue per flessibilitàIntegrazione con Tool Popolari
VS Code JSON Schema Validation
Configura VS Code per validare JSON con il tuo schema:
// settings.json
{
"json.schemas": [
{
"fileMatch": ["user-profile.json"],
"url": "./schemas/user-profile.schema.json"
}
]
}
Postman Schema Validation
Usa lo schema per validare risposte API in Postman:
// Test script
pm.test("Response matches schema", function() {
const schema = {
// Schema generato
}
pm.response.to.have.jsonSchema(schema)
})
Jest Testing
Valida dati nei test:
import Ajv from 'ajv'const ajv = new Ajv()
const schema = { / schema / }
const validate = ajv.compile(schema)
test('API response is valid', async () => {
const response = await fetch('/api/users/1')
const data = await response.json()
expect(validate(data)).toBe(true)
})
Limitazioni e Considerazioni
1. Inferenza Basata su Esempi
Lo schema generato si basa sull'esempio fornito. Se il tuo JSON ha:
{ "age": 30 }
Lo schema sarà "type": "integer", ma se in futuro age potrebbe essere null, dovrai aggiungere manualmente:
{ "type": ["integer", "null"] }
2. Array Eterogenei
Se l'array contiene tipi misti, il converter usa il primo elemento:
{
"items": [1, "two", true] // ❌ Difficile da gestire
}
Meglio usare array omogenei:
{
"numbers": [1, 2, 3],
"strings": ["one", "two"]
}
3. Riferimenti Circolari
Strutture con riferimenti circolari vengono rilevate e marcate:
{
"description": "Circular reference detected"
}
Dovrai gestirle manualmente con $ref.
Prossime Feature
Stiamo lavorando su:
Privacy e Open Source
Come tutti i nostri tool:
Prova Subito
Il JSON Schema Converter è disponibile gratuitamente:
Risorse Utili
Feedback
Hai suggerimenti? Trova un bug? Vuoi una feature?
---
Conclusione: Documentare e validare le tue API non è mai stato così facile. Il JSON Schema Converter ti fa risparmiare ore di lavoro manuale generando schemi accurati e pronti all'uso. Provalo oggi!