
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@json-eval-rs/react-native
Advanced tools
High-performance JSON Logic evaluator with schema validation for React Native
High-performance JSON Logic evaluator with schema validation for React Native.
Built with Rust for maximum performance, with native Android (Kotlin + JNI) and iOS (Objective-C++) bindings. All operations run asynchronously on background threads to keep your UI responsive.
useJSONEval hookyarn install @json-eval-rs/react-native
Or with Yarn:
yarn add @json-eval-rs/react-native
cd ios && pod install
No additional steps required. The library uses autolinking.
import { JSONEval } from '@json-eval-rs/react-native';
const schema = {
type: 'object',
properties: {
user: {
type: 'object',
properties: {
name: {
type: 'string',
rules: {
required: { value: true, message: 'Name is required' },
minLength: { value: 3, message: 'Min 3 characters' }
}
},
age: {
type: 'number',
rules: {
minValue: { value: 18, message: 'Must be 18+' }
}
}
}
}
}
};
// Create evaluator
const eval = new JSONEval({ schema });
// Evaluate
const data = { user: { name: 'John', age: 25 } };
const result = await eval.evaluate({ data });
console.log('Evaluated:', result);
// Validate
const validation = await eval.validate({ data });
if (validation.hasError) {
validation.errors.forEach(error => {
console.error(`${error.path}: ${error.message}`);
});
}
// Clean up
await eval.dispose();
import React, { useState } from 'react';
import { View, TextInput, Button, Text } from 'react-native';
import { useJSONEval } from '@json-eval-rs/react-native';
const schema = {
type: 'object',
properties: {
user: {
type: 'object',
properties: {
name: {
type: 'string',
rules: {
required: { value: true, message: 'Name is required' },
minLength: { value: 3, message: 'Min 3 characters' }
}
}
}
}
}
};
function MyForm() {
const eval = useJSONEval({ schema });
const [name, setName] = useState('');
const [errors, setErrors] = useState<string[]>([]);
const handleValidate = async () => {
if (!eval) return;
const data = { user: { name } };
const validation = await eval.validate({ data });
if (validation.hasError) {
setErrors(validation.errors.map(e => e.message));
} else {
setErrors([]);
console.log('Valid!');
}
};
return (
<View>
<TextInput
value={name}
onChangeText={setName}
placeholder="Enter name"
/>
<Button title="Validate" onPress={handleValidate} />
{errors.map((error, i) => (
<Text key={i} style={{ color: 'red' }}>{error}</Text>
))}
</View>
);
}
import React, { useState, useEffect } from 'react';
import { View, TextInput, Text } from 'react-native';
import { useJSONEval } from '@json-eval-rs/react-native';
const schema = {
type: 'object',
properties: {
quantity: { type: 'number' },
price: { type: 'number' },
total: {
type: 'number',
$evaluation: {
'*': [{ var: 'quantity' }, { var: 'price' }]
}
}
}
};
function Calculator() {
const eval = useJSONEval({ schema });
const [quantity, setQuantity] = useState(1);
const [price, setPrice] = useState(10);
const [total, setTotal] = useState(0);
useEffect(() => {
if (!eval) return;
const updateTotal = async () => {
const data = { quantity, price };
const result = await eval.evaluateDependents({
changedPaths: ['quantity'], // Array of changed field paths
data,
reEvaluate: false // Optional: re-evaluate entire schema after dependents
});
setTotal(result.total);
};
updateTotal();
}, [eval, quantity, price]);
return (
<View>
<TextInput
value={String(quantity)}
onChangeText={(val) => setQuantity(Number(val))}
keyboardType="numeric"
/>
<TextInput
value={String(price)}
onChangeText={(val) => setPrice(Number(val))}
keyboardType="numeric"
/>
<Text>Total: {total}</Text>
</View>
);
}
constructor(options: {
schema: string | object;
context?: string | object;
data?: string | object;
})
Creates a new evaluator instance.
Evaluates the schema with provided data.
async evaluate(options: {
data: string | object;
context?: string | object;
}): Promise<any>
Validates data against schema rules.
async validate(options: {
data: string | object;
context?: string | object;
}): Promise<ValidationResult>
Returns:
interface ValidationResult {
hasError: boolean;
errors: ValidationError[];
}
interface ValidationError {
path: string;
ruleType: string;
message: string;
}
Re-evaluates fields that depend on changed paths (processes transitively).
async evaluateDependents(options: {
changedPaths: string[]; // Array of field paths that changed
data?: string | object; // Optional updated data
context?: string | object; // Optional context
reEvaluate?: boolean; // If true, performs full evaluation after dependents
}): Promise<any[]>
Parameters:
changedPaths: Array of field paths that changed (e.g., ['field1', 'nested.field2'])data: Optional JSON data (string or object). If provided, replaces current datacontext: Optional context datareEvaluate: If true, performs full schema evaluation after processing dependents (default: false)Returns: Array of dependent field change objects with $ref, value, $field, $parentField, and transitive properties.
Example:
// Update multiple fields and get their dependents
const result = await eval.evaluateDependents({
changedPaths: ['illustration.insured.ins_dob', 'illustration.product_code'],
data: updatedData,
reEvaluate: true // Re-run full evaluation after dependents
});
// Process the changes
result.forEach(change => {
console.log(`Field ${change.$ref} changed:`, change.value);
});
Frees native resources. Must be called when done.
async dispose(): Promise<void>
Gets the library version.
static async version(): Promise<string>
React hook for automatic lifecycle management.
function useJSONEval(options: JSONEvalOptions): JSONEval | null
Returns null until initialized, then returns the JSONEval instance.
Automatically disposes on unmount.
Supported validation rules:
Typical performance on modern devices:
Native performance beats JavaScript-only solutions by 10-50x.
This library uses sequential processing by default, which is optimal for mobile devices. The Rust core supports an optional parallel feature using Rayon, but:
The default configuration is optimized for mobile performance and battery efficiency.
All async methods can throw errors:
try {
const result = await eval.evaluate({ data });
} catch (error) {
console.error('Evaluation error:', error.message);
}
Always dispose of instances when done:
const eval = new JSONEval({ schema });
try {
// Use eval
} finally {
await eval.dispose(); // Important!
}
Or use the hook for automatic management:
function MyComponent() {
const eval = useJSONEval({ schema }); // Auto-disposed on unmount
// Use eval
}
Full TypeScript support included. All types are exported:
import type {
JSONEval,
ValidationError,
ValidationResult,
JSONEvalOptions,
EvaluateOptions,
EvaluateDependentsOptions
} from '@json-eval-rs/react-native';
If you encounter build errors on iOS:
cd ios
rm -rf Pods Podfile.lock
pod install --repo-update
If you encounter build errors on Android:
cd android
./gradlew clean
cd ..
Then rebuild your app.
Make sure you've:
pod install on iOSSee the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
FAQs
High-performance JSON Logic evaluator with schema validation for React Native
We found that @json-eval-rs/react-native demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.