Skip to content

SchemaEditor

The SchemaEditor component provides an interactive table-based interface for creating and editing JSON schemas.

SchemaEditor allows users to define data structures by adding properties, specifying types, and configuring validation rules in a user-friendly table format.

  • Interactive property editing
  • Type selection from JSON schema types
  • Format specification for common patterns
  • Required/optional property flags
  • Array and object type support
  • Inline editing with validation
  • Add/remove properties
  • Read-only mode support
import { SchemaEditor } from '@cratis/components/SchemaEditor';
import { JsonSchema } from '@cratis/components/types';
function MySchemaEditor() {
const [schema, setSchema] = useState<JsonSchema>({
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' }
},
required: ['name']
});
return (
<SchemaEditor
schema={schema}
onChange={setSchema}
/>
);
}

The component works with JSON schemas following the JSON Schema specification:

{
type: 'object',
properties: {
propertyName: {
type: 'string' | 'number' | 'boolean' | 'object' | 'array',
format?: 'date' | 'time' | 'date-time' | 'email' | 'uri' | 'uuid' | ...,
// ... other validation rules
}
},
required: ['propertyName']
}

Properties are displayed in a table:

NameTypeFormatRequired
namestring-
emailstringemail
agenumber-
createdAtstringdate-time