Overview
Data binding in JSON Forms works through:- Scopes - JSON Pointers that reference data properties
- Paths - Runtime data paths computed from scopes
- Reducers - State management for data updates
- Validation - Automatic validation on data changes
The Core State
JSON Forms maintains its state in a Redux-like structure:packages/core/src/store/store.ts.
Data Flow
Scopes to Paths
JSON Forms converts JSON Schema scopes to data paths:Scope Format
Scopes use JSON Pointer syntax:Path Conversion
Frompackages/core/src/util/path.ts:
- Simple
- Nested
- With Special Characters
Updating Data
Data updates flow through the core reducer:UPDATE_DATA Action
Frompackages/core/src/reducers/core.ts:
handleChange in Renderers
Renderers receive ahandleChange function:
Validation
Validation happens automatically on every data update:Validation Modes
Validator Creation
Frompackages/core/src/reducers/core.ts:
Error Handling
Validation errors are AJV ErrorObjects:Path Composition
When dealing with nested forms, paths are composed:Complete Data Update Flow
1. User Interaction
2. Dispatch Action
3. Reducer Updates State
4. React Re-renders
Components connected to JSON Forms state re-render with new data and errors.Advanced: Custom Validation
You can provide additional errors:packages/core/src/reducers/core.ts:
State Updates
State only updates when necessary:Performance Considerations
Immutable Updates
Immutable Updates
JSON Forms uses immutable updates with lodash/fp:
Validation Caching
Validation Caching
Validators are cached and only recompiled when the schema changes:
Error Equality Check
Error Equality Check
Errors are compared for equality to prevent unnecessary updates:
Debugging Data Binding
View Current State
Trace Path Resolution
Best Practices
Use controlled components
Use controlled components
Always keep data in React state and pass it to JsonForms:
Handle validation errors
Handle validation errors
Display validation errors to users:
Use appropriate validation mode
Use appropriate validation mode
Choose the right mode for your use case:
ValidateAndShow- Real-time validation (default)ValidateAndHide- Validate but don’t show errors until submissionNoValidation- For read-only forms
Next Steps
Renderers
Learn how renderers use handleChange to update data
Validation
Advanced validation techniques and custom validators