### Run Example Application Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/examples/nextjs/INSURANCE_FORM_EXAMPLE.md Commands to install dependencies and start the development server for the Next.js example. ```bash cd bindings/web/examples/nextjs yarn install npm run dev ``` -------------------------------- ### Install and Start Development Server Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/README.md Commands to install project dependencies and launch the local development environment. ```bash # Install dependencies yarn install # Start development server yarn dev ``` -------------------------------- ### Run React Native Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/examples/rncli/INSURANCE_FORM_EXAMPLE.md Commands to install dependencies and run the React Native example application. ```bash cd bindings/react-native/examples/rncli yarn install npm run android # or npm run ios ``` -------------------------------- ### Quick Start Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/01.use-csharp.md A C# code example demonstrating how to use the JSONEval class for schema definition, evaluation, and validation. ```APIDOC ## Quick Start This example shows basic usage of the `JSONEval` class in C#. ```csharp using JsonEvalRs; using Newtonsoft.Json.Linq; // Define schema with validation rules and layout string schema = @"{ \"type\": \"object\", \"properties\": { \"email\": { \"type\": \"string\", \"rules\": { \"required\": { \"value\": true, \"message\": \"Email is required\" }, \"pattern\": { \"value\": \"^[^@]+@[^@]+\\.[^@]+$\", \"message\": \"Invalid email format\" } } } } }"; // Use 'using' block for automatic disposal using (var eval = new JSONEval(schema)) { // 1. Evaluate string data = @"{ \"email\": \"invalid-email\" }"; eval.Evaluate(data); // 2. Validate ValidationResult validation = eval.Validate(data); if (validation.HasError) { foreach (var error in validation.Errors) { Console.WriteLine($"Field: {error.Path}, Error: {error.Message}"); } } // 3. Get Evaluated Schema (includes computed properties) JObject result = eval.GetEvaluatedSchema(); } ``` ``` -------------------------------- ### Run Custom Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md After defining a custom example in `Cargo.toml`, you can run it using this command. ```bash cargo run --example my_example ``` -------------------------------- ### Reference Access Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/02.core.md Examples of using $ref and ref for data access. ```json // Data: {"$params": {"rate": 0.05}} {"$": "$params.rate"} // → 0.05 ``` ```json {"$": "#/properties/user/properties/name"} ``` ```json {"$": ["missing.field", "default"]} // → "default" ``` -------------------------------- ### Add Custom Example to Cargo.toml Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md To create a custom example, add a new entry to your `Cargo.toml` file specifying the example name and its path. ```toml [[example]] name = "my_example" path = "examples/my_example.rs" ``` -------------------------------- ### Run Example App (iOS) Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/README.md Command to run the React Native CLI example app on iOS. ```bash yarn rncli ios ``` -------------------------------- ### Run Example App (Android) Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/README.md Command to run the React Native CLI example app on Android. ```bash yarn rncli android ``` -------------------------------- ### Test React Native Package Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/PUBLISHING.md Navigate to the React Native bindings directory, install dependencies, build TypeScript, and run the example app to test the package. ```bash cd bindings/react-native # Install dependencies yarn install # Build TypeScript npm run prepare # Test in example app npm run example ``` -------------------------------- ### Run Basic Example (Cargo CLI) Source: https://github.com/byrizki/jsoneval-rs/blob/main/README.md Execute the basic example using the Cargo CLI. You can run all scenarios or target a specific one by its identifier. ```bash # Run all scenarios cargo run --example basic # Run specific scenario cargo run --example basic zcc # Enable comparison with expected results cargo run --example basic --compare ``` -------------------------------- ### Install Web/JavaScript/TypeScript Dependencies Source: https://github.com/byrizki/jsoneval-rs/blob/main/README.md Install the core web package and choose a backend implementation based on your environment. ```bash yarn add @json-eval-rs/webcore # Then add either specific backend: yarn add @json-eval-rs/bundler # (For Vite/Webpack) # OR yarn add @json-eval-rs/vanilla # (For Vanilla JS) ``` -------------------------------- ### Return Raw Value Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/11.utility.md Examples showing how to return raw objects, arrays, and complex structures. ```json {"return": {"status": "ok", "code": 200}} // → {"status": "ok", "code": 200} ``` ```json {"return": [1, 2, 3, 4, 5]} // → [1, 2, 3, 4, 5] ``` ```json {"return": { "user": {"name": "Alice", "role": "admin"}, "permissions": ["read", "write", "delete"] }} ``` ```json {"if": [ {"var": "error"}, {"return": {"error": true, "message": "Failed"}}, {"return": {"success": true, "data": []}} ]} ``` -------------------------------- ### Check Missing Keys Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/11.utility.md Examples demonstrating how to identify missing fields in data objects. ```json // Data: {"name": "Alice", "age": 30} {"missing": ["name", "age", "email"]} // → ["email"] ``` ```json // Data: {"name": "Alice", "age": 30} {"missing": ["name", "age"]} // → [] ``` ```json // Data: {"name": "Alice"} {"missing": "email"} // → ["email"] ``` ```json {"if": [ {"==": [{"length": {"missing": ["name", "email"]}}, 0]}, "Valid", "Missing required fields" ]} ``` ```json { "cat": [ "Missing: ", {"reduce": [ {"missing": ["name", "email", "age"]}, {"cat": [{"var": "accumulator"}, ", ", {"var": "current"}]}, "" ]} ] } ``` -------------------------------- ### Quick Start: Web Bundler Usage Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/03.use-web-node.md Example for frameworks like Vite or Webpack, initializing JSONEval by explicitly passing the WASM module. Remember to call evalInstance.free() after use. ```typescript import { JSONEval } from '@json-eval-rs/webcore'; import * as wasmModule from '@json-eval-rs/bundler'; // 1. Initialize // Explicitly passing wasmModule allows bundlers to handle the WASM loading correctly const evalInstance = new JSONEval({ schema: mySchema, wasmModule }); // 2. Evaluate const result = await evalInstance.evaluate({ data: myData }); // 3. Cleanup evalInstance.free(); ``` -------------------------------- ### Addition Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/03.arithmetic.md Various usage examples for the addition operator. ```json {"+": [1, 2, 3]} // → 6 {"+": [10, 20]} // → 30 ``` ```json // Data: {"price": 100, "tax": 10, "shipping": 5} {"+": [ {"var": "price"}, {"var": "tax"}, {"var": "shipping"} ]} // → 115 ``` ```json {"+": [ {"*": [{"var": "quantity"}, {"var": "price"}]}, {"var": "shipping"} ]} ``` ```json {"+": [42]} // → 42 ``` ```json {"+": []} // → 0 ``` -------------------------------- ### Run React Native App on iOS Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/BUILD.md Installs dependencies, sets up CocoaPods for iOS, and starts the iOS application for the React Native project. ```bash yarn install cd ios && pod install && cd .. yarn ios ``` -------------------------------- ### Build and Install Dependencies Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/examples/nextjs/README.md Commands to build the WASM bindings and install project dependencies. ```bash cd ../.. # Go to repo root ./build-bindings.sh web ``` ```bash cd examples/nextjs yarn install ``` -------------------------------- ### Run Benchmark Example (Cargo CLI) Source: https://github.com/byrizki/jsoneval-rs/blob/main/README.md Execute the benchmark example with various options for iterations, caching, and concurrency. Use `--release` for optimized performance. ```bash # Run with 100 iterations cargo run --example benchmark -- -i 100 zcc # Use ParsedSchema for efficient caching cargo run --release --example benchmark -- --parsed -i 100 zcc # Test concurrent evaluations (4 threads, 10 iterations each) cargo run --example benchmark -- --parsed --concurrent 4 -i 10 # Full benchmarking suite with comparison cargo run --release --example benchmark -- --parsed -i 100 --compare ``` -------------------------------- ### Installation Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/01.use-csharp.md Instructions on how to install the JsonEvalRs NuGet package using the .NET CLI or the NuGet Package Manager. ```APIDOC ## Installation Install the JsonEvalRs NuGet package using one of the following methods: **Using .NET CLI:** ```bash dotnet add package JsonEvalRs ``` **Using NuGet Package Manager:** ```bash Install-Package JsonEvalRs ``` ``` -------------------------------- ### Project File Structure Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/examples/nextjs/README.md Overview of the Next.js example directory layout. ```text examples/nextjs/ ├── components/ │ ├── FormValidator.tsx # Basic validation │ ├── DependentFields.tsx # Dependent field calculation │ └── WorkerExample.tsx # Web Worker usage ├── pages/ │ └── index.tsx # Main page with tabs └── package.json ``` -------------------------------- ### Install Dependencies Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/README.md Run this command to install project dependencies within the monorepo. ```bash yarn install ``` -------------------------------- ### Install JSONEval-Rs dependencies Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/04.use-react.md Install the web core API and the bundler target via yarn. ```bash yarn add @json-eval-rs/webcore @json-eval-rs/bundler ``` -------------------------------- ### Install @json-eval-rs/bundler Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/packages/bundler/README.md Install the @json-eval-rs/bundler package using yarn. ```bash yarn install @json-eval-rs/bundler # or yarn add @json-eval-rs/bundler ``` -------------------------------- ### Generate Range Options Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/11.utility.md Examples for generating UI dropdown options from numeric ranges. ```json {"RANGEOPTIONS": [18, 65]} // → [ // {"label": "18", "value": "18"}, // {"label": "19", "value": "19"}, // ... // {"label": "65", "value": "65"} // ] ``` ```json {"RANGEOPTIONS": [2020, 2024]} // → [ // {"label": "2020", "value": "2020"}, // {"label": "2021", "value": "2021"}, // {"label": "2022", "value": "2022"}, // {"label": "2023", "value": "2023"}, // {"label": "2024", "value": "2024"} // ] ``` ```json {"RANGEOPTIONS": [10, 5]} // → [] (min > max) ``` ```json {"RANGEOPTIONS": [ {"var": "minAge"}, {"var": "maxAge"} ]} ``` -------------------------------- ### Run Development Server Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/examples/nextjs/README.md Command to start the Next.js development server. ```bash yarn dev ``` -------------------------------- ### Logical AND Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/06.logical.md Demonstrates basic usage, short-circuiting, and multiple condition evaluation. ```json // Data: {"age": 25, "verified": true} {"and": [ {">": [{"var": "age"}, 18]}, {"var": "verified"} ]} // → true (both conditions met) ``` ```json {"and": [false, {"var": "never.evaluated"}]} // → false (stops at first false, doesn't error on missing path) ``` ```json {"and": [ {">": [{"var": "score"}, 70]}, {"<": [{"var": "score"}, 100]}, {"==": [{"var": "status"}, "active"]} ]} // → true only if all three conditions are true ``` -------------------------------- ### Check Minimum Present Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/11.utility.md Examples for validating that a specific count of keys exists in the data. ```json // Data: {"phone": "555-1234"} {"missing_some": [1, ["email", "phone"]]} // → [] (at least 1 present) ``` ```json // Data: {} {"missing_some": [1, ["email", "phone"]]} // → ["email", "phone"] (need at least 1) ``` ```json // Data: {"email": "a@b.com"} {"missing_some": [2, ["email", "phone", "address"]]} // → ["phone", "address"] (only 1 present, need 2) ``` ```json {"if": [ {"==": [ {"length": {"missing_some": [1, ["phone", "email"]]}}, 0 ]}, "Valid", "Provide at least phone or email" ]} ``` -------------------------------- ### Install JSONEval-Rs Dependencies Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/07.use-static-html.md Install the required packages locally using Yarn. ```bash yarn add @json-eval-rs/webcore @json-eval-rs/vanilla ``` -------------------------------- ### Understand ParsedSchema Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md Use the `basic_parsed` example to understand the `ParsedSchema` functionality. This command executes the basic_parsed example. ```bash cargo run --example basic_parsed ``` -------------------------------- ### Run MessagePack Schema Test Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md Use the `basic_msgpack` example for testing MessagePack schemas. This command executes the basic_msgpack example with the input 'zccbin'. ```bash cargo run --example basic_msgpack zccbin ``` -------------------------------- ### Variable Access Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/02.core.md Examples demonstrating basic, nested, array, and default value access using the var operator. ```json // Data: {"name": "Alice", "age": 30} {"var": "name"} // → "Alice" {"var": "age"} // → 30 ``` ```json // Data: {"user": {"profile": {"city": "NYC"}}} {"var": "user.profile.city"} // → "NYC" ``` ```json // Data: {"items": [1, 2, 3, 4, 5]} {"var": "items.0"} // → 1 {"var": "items.2"} // → 3 ``` ```json // Data: {"name": "Bob"} {"var": ["age", 25]} // → 25 (age missing, returns default) {"var": ["name", "Guest"]} // → "Bob" (name exists, returns actual value) ``` ```json // Data: [1, 2, 3] {"var": ""} // → [1, 2, 3] (returns entire data) ``` ```json // In map/filter, empty string refers to current element {"map": [[1, 2, 3], {"var": ""}]} // → [1, 2, 3] ``` -------------------------------- ### Run Basic JSON Schema Test Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md Use the `basic` example for quick JSON schema testing. This command executes the basic example with the input 'zcc'. ```bash cargo run --example basic zcc ``` -------------------------------- ### Install @json-eval-rs/webcore for NodeJS Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/03.use-web-node.md Install the webcore package and the node target for NodeJS environments. Requires yarn. ```bash yarn add @json-eval-rs/webcore @json-eval-rs/node ``` -------------------------------- ### Install Web/TypeScript Packages Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/01.getting-started/2.installation.md Install the core API and a backend package for web projects. Use @json-eval-rs/bundler for Vite/Webpack or @json-eval-rs/vanilla for Vanilla JS projects. ```bash # For projects using Vite/Webpack yarn add @json-eval-rs/webcore @json-eval-rs/bundler # For Vanilla JS browser projects yarn add @json-eval-rs/webcore @json-eval-rs/vanilla ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/examples/rncli/README.md Starts the Metro bundler, essential for running React Native applications. Use npm or Yarn. ```bash # using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install Package (Yarn) Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/README.md Use this command to install the React Native package using Yarn. ```bash yarn install @json-eval-rs/react-native ``` -------------------------------- ### Operator Selection Guide in jsoneval-rs Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/01.cheatsheet.md A guide to selecting the appropriate operator for common scenarios, comparing alternatives and explaining the rationale. ```markdown | Scenario | Use This | Not This | Why | |----------|----------|----------|-----| | String concatenation | `cat` | `+` | `+` coerces to numbers | | Type-safe comparison | `===` | `==` | Avoid type coercion surprises | | Null defaults | `ifnull` | nested `if` | Cleaner and explicit | | Array membership | `in` | `some` with `==` | More efficient | | Calculate age | `DATEDIF` | Year subtraction | Accounts for birthday | | Round currency | `round` with 2 decimals | `floor` or `ceiling` | Standard rounding | | Check all conditions | `all` | `reduce` with logic | Short-circuits, clearer | | Loop through numbers | `FOR` | `reduce` tricks | Purpose-built | ``` -------------------------------- ### Install C# / .NET NuGet Package Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/01.getting-started/2.installation.md Install the JsonEvalRs NuGet package for your C# or .NET project using the .NET CLI. ```bash dotnet add package JsonEvalRs ``` -------------------------------- ### Install JSONEval-Rs dependencies Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/05.use-nextjs.md Install the necessary packages based on your build system. Use the bundler target for Webpack or the vanilla target for Turbopack. ```bash yarn add @json-eval-rs/webcore @json-eval-rs/node @json-eval-rs/bundler ``` ```bash yarn add @json-eval-rs/webcore @json-eval-rs/node @json-eval-rs/vanilla ``` -------------------------------- ### Install iOS Pods for @json-eval-rs/react-native Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/packages/react-native/README.md Navigate to the ios directory and run this command to install the necessary CocoaPods for iOS development. ```bash cd ios && pod install ``` -------------------------------- ### Install JSONEval-Rs Packages for Nuxt Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/06.use-nuxtjs.md Install the necessary Node.js bindings for server-side rendering and the bundler package for client-side integration with Vite/Webpack. ```bash yarn add @json-eval-rs/webcore @json-eval-rs/node @json-eval-rs/bundler ``` -------------------------------- ### Run Validation with Compare Flag Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md Use the `--compare` flag with the `basic` example for validation purposes. This command compares the results of the basic example. ```bash cargo run --example basic -- --compare ``` -------------------------------- ### Legacy API Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/03.advance-guide/04.compiled-logic-store.md Deprecated approach for evaluating logic, not recommended for FFI. ```rust let compiled = CompiledLogic::compile(&logic)?; let result = evaluator.evaluate(&compiled, &data)?; ``` -------------------------------- ### Cache Debug Output Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/EVALUATION_CACHE.md Illustrates example output from cache debug logging, showing HIT/MISS messages with details on cache tiers, item indices, table indices, and version mismatches. ```text Cache HIT #/$params/references/RIDER_ZLOS_TABLE Cache HIT [T2 table idx=0] #/$params/references/ZLOS_RATE Cache MISS #/$params/references/RIDER_ZLOS_TABLE: dep /$params/references/ZLOS_RATE changed (1 -> 2) Cache MISS #/$params/others/RIDER_FIRST_PREM_PER_PAY_TABLE/2/premi: dep /$params/references/RIDER_ZLOS_TABLE changed (1 -> 3) ``` -------------------------------- ### Quick Start Validation Source: https://github.com/byrizki/jsoneval-rs/blob/main/README.md Initialize the evaluator with a schema and perform data validation. ```rust use json_eval_rs::JSONEval; fn main() -> Result<(), Box> { let schema = r#"{ "type": "object", "properties": { "name": { "rules": { "required": { "value": true, "message": "Name is required" } } } } }"#; let mut eval = JSONEval::new(schema, None, None)?; let data = r#"{"name": "John Doe"}"#; eval.evaluate(data, None)?; let result = eval.get_evaluated_schema(false); // Validate the data let validation = eval.validate(data, None, None)?; if !validation.has_error { println!("✅ Data is valid!"); } else { println!("❌ Validation errors: {:?}", validation.errors); } Ok(()) } ``` ```csharp using JsonEvalRs; var schema = @"{ ""type"": ""object"", ""properties"": { ""age"": { ""rules"": { ""minValue"": { ""value"": 18, ""message"": ""Must be 18 or older"" } } } } }"; using (var eval = new JSONEval(schema)) { var data = @"{""age"": 25}"; var result = eval.Evaluate(data); var validation = eval.Validate(data); if (!validation.HasError) { Console.WriteLine("✅ Data is valid!"); } } ``` -------------------------------- ### Build project from source Source: https://github.com/byrizki/jsoneval-rs/blob/main/README.md Standard commands to clone, build, test, and run the project locally. ```bash # Clone the repository git clone https://github.com/byrizki/jsoneval-rs.git cd json-eval-rs # Build the core library cargo build --release # Run tests cargo test # Build all language bindings ./build-bindings.sh all # Run CLI tool with examples cargo run --bin json-eval-cli ``` -------------------------------- ### Install Rust Dependency Source: https://github.com/byrizki/jsoneval-rs/blob/main/README.md Add the library to your Cargo.toml file. ```toml [dependencies] json-eval-rs = "0.0.86" ``` -------------------------------- ### Run React Native App on Android Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/BUILD.md Installs dependencies and starts the Android application for the React Native project, ensuring the local package is included. ```bash yarn install yarn android ``` -------------------------------- ### Run Cache Demonstration Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/03.advance-guide/05.parsed-schema-cache.md Execute the provided cache demonstration example via cargo. ```bash cargo run --example cache_demo ``` -------------------------------- ### Basic Power Operations Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/03.arithmetic.md Basic exponentiation examples. ```json {"^": [2, 3]} // → 8 (2³) {"pow": [10, 2]} // → 100 (10²) ``` -------------------------------- ### Quick Start Evaluation Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/00.use-rust.md Initialize the engine with a schema and data, then evaluate to produce a result. ```rust use json_eval_rs::JSONEval; fn main() -> Result<(), String> { let schema = r#"{ "type": "object", "properties": { "email": { "type": "string", "rules": { "required": { "value": true, "message": "Email is required" }, "pattern": { "value": "^[^@]+@[^@]+\\.[^@]+$", "message": "Invalid email format" } } } } }"#; let data = r#"{ "email": "invalid-email" }"#; // 1. Initialize let mut eval = JSONEval::new(schema, None, Some(data)) .map_err(|e| e.to_string())?; // 2. Evaluate eval.evaluate(data, None, None, None)?; // 3. Get evaluated schema let result = eval.get_evaluated_schema(false); println!("{}", serde_json::to_string_pretty(&result).unwrap()); Ok(()) } ``` -------------------------------- ### Quick Start: NodeJS Usage Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/03.use-web-node.md Example of using JSONEval in NodeJS, importing the node package and registering native bindings. Ensure to call evalInstance.free() in a finally block. ```typescript import { JSONEval } from '@json-eval-rs/webcore'; import '@json-eval-rs/node'; const run = async () => { const evalInstance = new JSONEval({ schema }); try { const result = await evalInstance.validate({ data }); console.log(result.has_error); } finally { evalInstance.free(); } }; run(); ``` -------------------------------- ### Quick Start: Web Vanilla Usage Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/03.use-web-node.md Example for standard browser environments without a bundler, initializing JSONEval with the vanilla WASM module. Ensure to call evalInstance.free() when done. ```typescript import { JSONEval } from '@json-eval-rs/webcore'; import * as wasmModule from '@json-eval-rs/vanilla'; // Initialize exactly the same way as the bundler method: const evalInstance = new JSONEval({ schema: mySchema, wasmModule }); // ... Evaluate and free evalInstance.free(); ``` -------------------------------- ### Install json-eval-rs Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/00.use-rust.md Add the dependency to your project using cargo or by editing Cargo.toml. ```bash cargo add json-eval-rs ``` ```toml [dependencies] json-eval-rs = "0.0.86" ``` -------------------------------- ### Multiplication Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/03.arithmetic.md Various usage examples for the multiplication operator. ```json {"*": [2, 3, 4]} // → 24 {"*": [5, 6]} // → 30 ``` ```json // Data: {"quantity": 5, "price": 10} {"*": [{"var": "quantity"}, {"var": "price"}]} // → 50 ``` ```json {"*": [{"var": "amount"}, 0.15]} // 15% of amount ``` ```json {"*": []} // → 0 (special case for compatibility) ``` -------------------------------- ### Basic Arithmetic Operations Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/03.arithmetic.md Demonstrates basic division, modulo, and power operations with examples. ```APIDOC ## Division (`/`) ### Description Performs division. Handles division by zero by returning null. ### Syntax ```json {"/": [dividend, divisor]} ``` ### Parameters - **dividend** (number): The number to be divided. - **divisor** (number): The number to divide by. ### Return Type Number - The result of the division, or `null` if the divisor is zero. ### Examples **Basic division:** ```json {"/": [10, 2]} // → 5 {"/": [100, 5, 2]} // → 10 (100 / 5 / 2) ``` **Division by zero:** ```json {"/": [10, 0]} // → null ``` **Empty array:** ```json {"/": []} // → 0 ``` ## `%` - Modulo ### Description Returns the remainder of a division. ### Syntax ```json {"%": [dividend, divisor]} ``` ### Parameters - **dividend** (number): Value to divide. - **divisor** (number): Value to divide by. ### Return Type Number - Remainder, or `null` if divisor is zero. ### Examples **Basic modulo:** ```json {"%": [7, 3]} // → 1 {"%": [10, 5]} // → 0 {"%": [15, 4]} // → 3 ``` **Modulo by zero:** ```json {"%": [5, 0]} // → null ``` ## `^` / `pow` - Power ### Description Raises a number to a power. ### Syntax ```json {"^": [base, exponent]} {"pow": [base, exponent]} ``` ### Parameters - **base** (number): Base number. - **exponent** (number): Power to raise to. ### Return Type Number - Result of base^exponent. ### Examples **Basic power:** ```json {"^": [2, 3]} // → 8 (2³) {"pow": [10, 2]} // → 100 (10²) ``` **Square root:** ```json {"pow": [9, 0.5]} // → 3 (√9) {"pow": [16, 0.5]} // → 4 (√16) ``` **Negative exponents:** ```json {"pow": [2, -1]} // → 0.5 (1/2) {"pow": [10, -2]} // → 0.01 (1/100) ``` **Zero power:** ```json {"pow": [5, 0]} // → 1 (any number⁰ = 1) ``` ``` -------------------------------- ### Subtraction Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/03.arithmetic.md Various usage examples for the subtraction operator. ```json {"-": [10, 3]} // → 7 {"-": [100, 20, 5]} // → 75 (100 - 20 - 5) ``` ```json {"-": [5]} // → -5 {"-": [-10]} // → 10 ``` ```json // Data: {"total": 100, "discount": 15} {"-": [{"var": "total"}, {"var": "discount"}]} // → 85 ``` ```json {"-": [ {"year": {"today": null}}, {"var": "birthYear"} ]} ``` -------------------------------- ### Build NuGet Package Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/PUBLISHING.md Navigates to the C# bindings directory and builds the NuGet package. ```bash cd bindings/csharp dotnet pack -c Release ``` -------------------------------- ### Complete Instrumentation Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/03.advance-guide/06.timing-instrumentation.md Demonstrates clearing data, performing evaluation, and printing the summary. ```rust use json_eval_rs::JSONEval; fn main() { // Clear any previous timing data json_eval_rs::clear_timing_data(); // Your code here let mut eval = JSONEval::new(schema, None, Some(data))?; eval.evaluate(data, None)?; let result = eval.get_evaluated_schema(false); // Print timing summary (only shows output if JSONEVAL_TIMING=1) json_eval_rs::print_timing_summary(); } ``` ```csharp // Timing instrumentation is a native Rust debugging feature. // Standard usage triggers native timing logs automatically if JSONEVAL_TIMING=1 is configured in the environment. ``` ```typescript // Timing instrumentation is a native Rust debugging feature. // Standard usage triggers native timing logs automatically if JSONEVAL_TIMING=1 is configured in the environment. ``` ```typescript // Timing instrumentation is a native Rust debugging feature. // Standard usage triggers native timing logs automatically if JSONEVAL_TIMING=1 is configured in the environment. ``` -------------------------------- ### Serve Static Files with npx serve Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/examples/web-benchmark/README.md Use npx serve to start a static HTTP server for the web benchmark files. Ensure you are in the correct directory. ```bash npx serve bindings/web/examples/web-benchmark ``` -------------------------------- ### Benchmark Output Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/examples/nodejs-benchmark/README.md Sample console output showing parse and evaluation times for the zcc scenario. ```text 🚀 JSON Eval RS - Node.js WASM Benchmark 📦 WASM version: 0.0.86 📋 Scenario: 'zcc' 📁 Project Root: /path/to/jsoneval-rs ================================================== 🎯 Running Node.js WASM Benchmark ================================================== Scenario: zcc Schema: /path/to/samples/zcc.json Data: /path/to/samples/zcc-data.json 📂 Loading files... ⏱️ Running evaluation... 📝 Parse (new): 312.451ms ⚡ Eval: 209.873ms ⏱️ Total: 522.324ms 💾 Saving results... ✅ Results saved ================================================== 📊 Benchmark Summary ================================================== 🟦 Node.js (WASM): Total: 522.324ms - Parse: 312.451ms - Eval: 209.873ms 💾 Memory Usage: Heap Used: 45.23 MB RSS: 112.67 MB ✅ Benchmark completed successfully! ``` -------------------------------- ### Logical OR Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/06.logical.md Demonstrates basic usage, default value assignment, and multiple fallbacks. ```json // Data: {"premium": false, "trial": true} {"or": [ {"var": "premium"}, {"var": "trial"} ]} // → true (trial is truthy) ``` ```json {"or": [ {"var": "username"}, {"var": "email"}, "Guest" ]} // Returns first available value or "Guest" ``` ```json {"or": [ {"var": "primary.value"}, {"var": "secondary.value"}, {"var": "tertiary.value"}, 0 ]} ``` -------------------------------- ### Build Documentation for Deployment Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/README.md Command to manually build the documentation site for GitHub Pages deployment. ```bash NUXT_APP_BASE_URL=/jsoneval-rs/ yarn nuxt build --preset github_pages ``` -------------------------------- ### Get Integer Part with Trunc Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/04.math.md Removes the fractional part of a number to get its integer component. ```json {"trunc": [{"var": "decimal"}]} ``` -------------------------------- ### Test Web Package Locally Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/PUBLISHING.md Navigates to the web bindings directory, runs tests, creates a tarball, and installs it locally in a test project. ```bash cd bindings/web # Run local tests npm test # Test packaging npm pack # Install locally in test project cd /path/to/test/project yarn install /path/to/json-eval-rs/bindings/web/json-eval-rs-web-0.0.1.tgz ``` -------------------------------- ### Apply best practices for logic Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/06.logical.md Recommended patterns for performance and readability. ```json {"and": [{"var": "enabled"}, expensiveCalculation]} ``` ```json {"ifnull": [{"var": "value"}, "default"]} // ✓ Clear {"if": [{"var": "value"}, {"var": "value"}, "default"]} // ✗ Verbose ``` ```json {"and": [condition1, condition2, condition3]} // ✓ {"and": [condition1, {"and": [condition2, condition3]}]} // ✗ Unnecessary nesting ``` ```json {"!": {"isempty": {"var": "required.field"}}} ``` -------------------------------- ### Run CLI with full options Source: https://github.com/byrizki/jsoneval-rs/blob/main/README.md Executes the CLI tool with MessagePack support, comparison paths, and iteration benchmarking. ```bash cargo run --bin json-eval-cli -- schema.bform \ --data data.bform \ --compare expected.json \ --compare-path "$.$params.others" \ --parsed \ --iterations 100 \ --output result.json ``` -------------------------------- ### Install cargo-ndk for Android Builds Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/BUILD.md Installs the cargo-ndk utility, which is required for building Rust code for Android targets. ```bash cargo install cargo-ndk ``` -------------------------------- ### Migration Guide Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/03.advance-guide/04.compiled-logic-store.md Compares the old and new API approaches, recommending the new FFI-friendly method. ```APIDOC ## Migration Guide ### Old API (Not Recommended for FFI) - **Issues**: `CompiledLogic` cannot cross FFI boundaries, requires serialization/deserialization, cannot be shared between instances. ### New API (Recommended) - **Benefits**: ID is FFI-safe (`u64`), logic is stored globally and can be shared across instances, automatic deduplication. #### Rust Native Usage ```rust let logic_id = eval.compile_logic(logic_str)?; let result = eval.run_logic(logic_id, Some(&data), None)?; ``` #### FFI-Friendly Usage ```c uint64_t id = json_eval_compile_logic(handle, logic_str); result_t res = json_eval_run_logic(handle, id, data, context); ``` ``` -------------------------------- ### Install @json-eval-rs/webcore with Bundler Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/packages/core/README.md Install the bridge and the target WASM package for use with bundlers like Webpack, Vite, or Next.js. ```bash # Install bridge + your target WASM package yarn install @json-eval-rs/webcore @json-eval-rs/bundler ``` ```bash # Or for direct browser use yarn install @json-eval-rs/webcore @json-eval-rs/vanilla ``` ```bash # Or for Node.js yarn install @json-eval-rs/webcore @json-eval-rs/node ``` -------------------------------- ### Build the C# Benchmark Project Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/csharp-example/README.md Compiles the C# benchmark project using the .NET CLI in Release mode. ```bash cd bindings/csharp-example dotnet build --configuration Release ``` -------------------------------- ### Run Performance Benchmark Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md For performance testing, use the `benchmark` example with `--parsed` and `--release` flags. This command runs the benchmark with 100 iterations for input 'zcc'. ```bash cargo run --release --example benchmark -- --parsed -i 100 zcc ``` -------------------------------- ### Identifying Bottlenecks Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/03.advance-guide/06.timing-instrumentation.md Example of how to identify performance bottlenecks based on absolute and relative execution times. ```text parse_schema 315ms ← PRIMARY BOTTLENECK (35%) process batches 327ms ← SECONDARY BOTTLENECK (37%) resolve_layout 2ms ← Not a concern (<1%) ``` -------------------------------- ### Install JSON Eval RS for React Native Source: https://context7.com/byrizki/jsoneval-rs/llms.txt Add the @json-eval-rs/react-native package to your React Native project and install iOS pods. ```bash yarn add @json-eval-rs/react-native cd ios && pod install ``` -------------------------------- ### New API Migration Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/03.advance-guide/04.compiled-logic-store.md Recommended approach for using the new ID-based API in both Rust and FFI contexts. ```rust // Rust native let logic_id = eval.compile_logic(logic_str)?; let result = eval.run_logic(logic_id, Some(&data), None)?; // FFI-friendly uint64_t id = json_eval_compile_logic(handle, logic_str); result_t res = json_eval_run_logic(handle, id, data, context); ``` -------------------------------- ### Run Basic JSON Schema Scenarios Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md Executes JSON schema evaluations using the basic example runner. ```bash # Run all JSON schema scenarios cargo run --example basic # Run specific scenario cargo run --example basic zcc # Enable comparison with expected results cargo run --example basic --compare ``` -------------------------------- ### Install React Native Module Dependencies Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/BUILD.md Navigates to the React Native bindings directory and installs the project dependencies using Yarn. ```bash cd bindings/react-native yarn install ``` -------------------------------- ### Search for Second Occurrence Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/07.string.md Demonstrates finding the second occurrence of a substring using a 1-based start position. The start position is inclusive. ```json // Data: {"text": "Hello Hello World"} // Find second occurrence of "Hello" {"search": ["Hello", {"var": "text"}, 7]} // 1-based, starts after first "Hello" // → 7 (finds second "Hello") ``` -------------------------------- ### Run Basic MessagePack Schema Scenarios Source: https://github.com/byrizki/jsoneval-rs/blob/main/examples/README.md Executes MessagePack schema evaluations using the basic_msgpack example runner. ```bash # Run all MessagePack schema scenarios cargo run --example basic_msgpack # Run with comparison cargo run --example basic_msgpack --compare zccbin ``` -------------------------------- ### Old API Usage Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/ARCHITECTURE.md This TypeScript example shows the previous API where the WASM module had to be explicitly imported and passed to the JSONEval constructor. ```typescript import { JSONEval } from '@json-eval-rs/webcore'; import * as wasmModule from '@json-eval-rs/bundler'; const evaluator = new JSONEval({ schema, wasmModule }); ``` -------------------------------- ### Build and Run Release Version for Benchmarking Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/02.how-to/08.use-cli.md Compiles the CLI in release mode for accurate performance measurements and runs it with a large number of iterations. Use `--parsed` to parse the schema once and `--no-output` to skip result serialization for pure evaluation timing. ```bash cargo build --release --bin json-eval-cli ./target/release/json-eval-cli schema.json -d data.json --parsed -i 1000 ``` -------------------------------- ### Install iOS Dependencies with CocoaPods Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/BUILD.md Navigates to the iOS directory within the React Native bindings and installs the project dependencies using CocoaPods. ```bash cd ios pod install ``` -------------------------------- ### Install Rust Targets for Android and iOS Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/react-native/BUILD.md Installs the necessary Rust toolchain targets for cross-compiling the Rust library for Android and iOS development. ```bash # Android targets rustup target add aarch64-linux-android rustup target add armv7-linux-androideabi rustup target add x86_64-linux-android rustup target add i686-linux-android # iOS targets rustup target add aarch64-apple-ios rustup target add x86_64-apple-ios rustup target add aarch64-apple-ios-sim ``` -------------------------------- ### Complex Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/06.logical.md Illustrative examples demonstrating the combination of various operators for sophisticated logic like access control, tiered pricing, and multi-rule validation. ```APIDOC ## Complex Examples ### Access Control ```json {"and": [ {"var": "user.authenticated"}, {"or": [ {"==": [{"var": "user.role"}, "admin"]}, {"==": [{"var": "resource.owner"}, {"var": "user.id"}]} ]} ]} ``` ### Tiered Pricing ```json {"if": [ {">": [{"var": "quantity"}, 100]}, {"*": [{"var": "price"}, 0.7]}, {"if": [ {">": [{"var": "quantity"}, 50]}, {"*": [{"var": "price"}, 0.85]}, {"var": "price"} ]} ]} ``` ### Validation with Multiple Rules ```json {"and": [ {"!": {"isempty": {"var": "email"}}}, {">": [{"length": {"var": "password"}}, 8]}, {"var": "terms_accepted"}, {"xor": [ {"var": "phone"}, {"var": "backup_email"} ]} ]} ``` ``` -------------------------------- ### Initialize Web Worker and DOM Elements Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/examples/web-benchmark/index.html Sets up the Web Worker for the benchmark and gets references to necessary DOM elements. Ensure the worker script is correctly located. ```javascript const workerUrl = new URL("./worker.js", import.meta.url).href; const worker = new Worker(workerUrl, { type: "module" }); const logBox = document.getElementById("log-box"); const runBtn = document.getElementById("run-btn"); const spinner = document.getElementById("spinner"); const statusDot = document.getElementById("status-dot"); const statusTxt = document.getElementById("status-text"); ``` -------------------------------- ### Date Less Than Comparison Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/05.comparison.md Compares a start date variable against the current date ('today') to check if the start date is in the past. Requires 'today' function. ```json {"<": [{"var": "startDate"}, {"today": null}]} ``` -------------------------------- ### VALUEAT Usage Examples Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/10.table.md Demonstrates retrieving rows, specific columns, handling out-of-bounds indices, and dynamic lookups. ```json {"VALUEAT": [{"var": "table"}, 1]} ``` ```json {"VALUEAT": [{"var": "table"}, 1, "name"]} {"VALUEAT": [{"var": "table"}, 2, "age"]} ``` ```json {"VALUEAT": [{"var": "table"}, -1]} {"VALUEAT": [{"var": "table"}, 999]} ``` ```json {"VALUEAT": [ {"var": "rates"}, {"INDEXAT": [{"var": "age"}, {"var": "rates"}, "minAge"]}, "rate" ]} ``` ```json {"FOR": [ 0, {"-": [{"length": {"var": "table"}}, 1]}, {"VALUEAT": [{"var": "table"}, {"var": "$iteration"}, "value"]} ]} ``` -------------------------------- ### Install JSON Eval RS for Web/Node.js Source: https://context7.com/byrizki/jsoneval-rs/llms.txt Install the necessary packages for using JSON Eval RS in a web (with bundlers or vanilla JS) or Node.js environment. ```bash # For bundlers (Vite, Webpack, Next.js) yarn add @json-eval-rs/webcore @json-eval-rs/bundler # For Node.js yarn add @json-eval-rs/webcore @json-eval-rs/node # For vanilla browser yarn add @json-eval-rs/webcore @json-eval-rs/vanilla ``` -------------------------------- ### Create New Web API Project Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/csharp/DI_WEBAPI_GUIDE.md Commands to scaffold a new Web API project and include the JsonEvalRs package. ```bash dotnet new webapi -n JsonEvalDemo cd JsonEvalDemo dotnet add package JsonEvalRs ``` -------------------------------- ### New API Usage Example Source: https://github.com/byrizki/jsoneval-rs/blob/main/bindings/web/ARCHITECTURE.md This TypeScript example demonstrates the new, simplified API where the JSONEval class is imported directly from the target package (e.g., '@json-eval-rs/bundler'), and the WASM module is auto-injected. ```typescript import { JSONEval } from '@json-eval-rs/bundler'; const evaluator = new JSONEval({ schema }); ``` -------------------------------- ### Price Comparison with Discount Calculation Source: https://github.com/byrizki/jsoneval-rs/blob/main/docs/content/en/04.operators/05.comparison.md Calculates a discounted price using 'let' bindings for original price and discount percentage, then verifies if the discounted price is less than the original. ```json { "let": { "originalPrice": {"var": "price"}, "discountedPrice": {"*": [ {"var": "price"}, {"-": [1, {"/": [{"var": "discountPercent"}, 100]}]} ]} }, "in": { "<": [{"var": "discountedPrice"}, {"var": "originalPrice"}] } } ```