diff --git a/README.md b/README.md index f29c590..413da2b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# A New JSON Schema -A JSON Schema is crucial for making communication, interoperability, validation, testing, documentation, and specification seamless. All of this combined contributes to better maintenance and evolution of data-driven applications and systems. If you are interested in an overview of the roles and usage of JSON Schema in modern web applications, check out our in-depth post [here](https://www.relogiclabs.com/2023/01/the-roles-of-json-schema.html). +# JSchema - The New JSON Schema +A JSON Schema is crucial for making communication, interoperability, validation, testing, documentation, and specification seamless. All of this combined contributes to better maintenance and evolution of data-driven applications and systems. If you are interested in a comprehensive overview of the roles and uses of JSON Schema in modern web applications, check out our in-depth post [here](https://www.relogiclabs.com/2023/01/the-roles-of-json-schema.html). ## Design Goals The traditional standard JSON Schema rigorously follows the conventional JSON structure, which unfortunately comes at the expense of simplicity, conciseness, and readability. Our goal is to develop a new JSON Schema that promotes these essential aspects that were previously missing. @@ -10,7 +10,7 @@ This new schema is simple, lucid, easy to grasp, and doesn't require much prior Let's explore an example of our schema for a typical JSON API response containing information about a user profile or account. The schema is very self-explanatory and thus almost no prior knowledge is required to understand the schema and the JSON responses specified by this schema. ```cpp %title: "User Profile Response" -%version: 1.0.0 +%version: "1.0.0-basic" %schema: { "user": { @@ -63,11 +63,10 @@ In the above example, two types of constraints are used: constraint functions (a } ``` ## Extended Example -The next example represents an expanded version of the previous one, which brings more complexity. To effectively construct such schemas with multiple layers of nested structures, it's beneficial to have a fundamental understanding of this schema format. While the syntax may seem difficult at first, it becomes straightforward once you have a basic understanding of it. For more detailed information, reference documentation is available [here](https://relogiclabs.github.io/JSchema-Java/articles/introduction). +The next example represents an expanded version of the previous one, which brings more complexity. To effectively construct such schemas with multiple layers of nested structures, including custom validation functions, it's beneficial to have a fundamental understanding of this schema syntax. While the syntax may seem difficult at first, it becomes straightforward once you have a basic understanding of it. For more detailed information, reference documentation is available [here](https://relogiclabs.github.io/JSchema-Java/articles/introduction). ```cpp %title: "Extended User Profile Dashboard API Response" -%version: 2.0.0 -%include: com.relogiclabs.json.schema.external.ExternalFunctions +%version: "2.0.0-extended" %pragma DateDataTypeFormat: "DD-MM-YYYY" %pragma TimeDataTypeFormat: "DD-MM-YYYY hh:mm:ss" @@ -133,6 +132,17 @@ The next example represents an expanded version of the previous one, which bring "isCloudy": #boolean } } + +%script: { + constraint function checkAccess(role) { + // Receiver &role received only one value + // 'target' keyword refers to the target JSON value + if(role[0] == "user" && target > 5) return fail( + "ERRACCESS01", "Data access incompatible with 'user' role", + expected("an access at most 5 for 'user' role"), + actual("found access " + target + " which is greater than 5")); + } +} ``` The subsequent JSON sample is an illustrative example that successfully validates against the expanded schema mentioned earlier. Within this example, recurring JSON structures appear that can be validated by defining components or nested functions and data types. Besides, reusing simple component definitions, you can achieve a clear and concise schema when validating large JSON with repetitive structures instead of duplicating or referring to various structures across the schema. This improves the overall readability and maintainability of the schema. ```json diff --git a/doc/content/_index.md b/doc/content/_index.md index 12b3228..c1fa794 100644 --- a/doc/content/_index.md +++ b/doc/content/_index.md @@ -4,9 +4,9 @@ date = 2023-10-08T09:38:53+06:00 +++ # Introduction -The New JSON Schema prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements. +JSchema, a new JSON Schema, prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements. -JSON, short for JavaScript Object Notation, is one of the most widely used data exchange formats that are both user-friendly and machine-readable. New JSON Schema is a practical tool for defining and validating the structure of JSON documents. The following guides offer comprehensive details about the New JSON Schema. This document provides a list of links, each corresponding to a specific detail document available in this project. +JSON, short for JavaScript Object Notation, is one of the most widely used data exchange formats that are both user-friendly and machine-readable. JSchema is a practical tool for defining and validating the structure of JSON documents. The following guides provide comprehensive details about the JSchema.
* [Getting Started & Installation](/JSchema-Java/articles/quickstart) @@ -15,9 +15,10 @@ JSON, short for JavaScript Object Notation, is one of the most widely used data * [Schema Specification & Grammar](/JSchema-Java/articles/specification) * [Data Types & Validation](/JSchema-Java/articles/datatypes) * [Functions & Validation](/JSchema-Java/articles/functions) + * [JSchema CScript & Validation](/JSchema-Java/articles/cscript) * [Date & Time Patterns](/JSchema-Java/articles/datetime) * [Defining Schema Components](/JSchema-Java/articles/components) * [Build from Source Code](/JSchema-Java/articles/sourcebuild) * [API Reference Documentation](/JSchema-Java/api/index.html) * [GitHub Source Code Repository](https://github.com/relogiclabs/JSchema-Java) -
+
\ No newline at end of file diff --git a/doc/content/articles/_index.md b/doc/content/articles/_index.md index e80ad01..724428e 100644 --- a/doc/content/articles/_index.md +++ b/doc/content/articles/_index.md @@ -3,4 +3,4 @@ title = 'Articles' date = 2023-10-08T09:38:53+06:00 +++ -The New JSON Schema prioritizes simplicity, conciseness, and readability, making it user-friendly and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements. +JSchema, a new JSON Schema, prioritizes simplicity, conciseness, and readability, ensuring user-friendliness and accessibility without requiring extensive prior knowledge. It offers efficient read-write capabilities, precise JSON document definition through various data types and functions, and extensibility to address the diverse requirements of modern web services. \ No newline at end of file diff --git a/doc/content/articles/components.md b/doc/content/articles/components.md index b13b072..578f2b2 100644 --- a/doc/content/articles/components.md +++ b/doc/content/articles/components.md @@ -1,7 +1,7 @@ +++ title = 'Components' date = 2023-12-15T09:38:53+06:00 -weight = 9 +weight = 10 +++ # Schema Components @@ -45,19 +45,19 @@ By defining a reusable schema component with a clear and descriptive name, one c "id": 1, "title": "Getting Started", "preview": "This guide will show you through the essential steps to quickly...", - "tags": ["JSON", "Json Schema", "Quick Start"] + "tags": ["JSON", "JSchema", "Quick Start"] }, { "id": 2, "title": "Validation Syntax", "preview": "A JSON document is a structured data format used for the exchange...", - "tags": ["JSON", "Json Schema", "Validation Syntax"] + "tags": ["JSON", "JSchema", "Validation Syntax"] }, { "id": 3, "title": "Constraint Functions", "preview": "This document serves as a brief overview, providing key insights into...", - "tags": ["JSON", "Json Schema", "Constraint Functions"] + "tags": ["JSON", "JSchema", "Constraint Functions"] } ] ``` \ No newline at end of file diff --git a/doc/content/articles/cscript.md b/doc/content/articles/cscript.md new file mode 100644 index 0000000..48b0e6e --- /dev/null +++ b/doc/content/articles/cscript.md @@ -0,0 +1,97 @@ ++++ +title = 'CScript DSL' +date = 2024-01-25T09:38:53+06:00 +weight = 8 ++++ + +# CScript Domain-Specific Language +CScript, a domain-specific scripting language, designed specifically for JSchema document. This lightweight, interpreted, and dynamically typed C-style language seamlessly integrates with the foundational principles of the existing JSchema architecture. With the use of dynamic typing and programming constructs similar to both JSON and JavaScript, streamlines the process of writing concise, user-friendly, and flexible logic for constraint or validation functions. + +Although CScript is similar to JavaScript in many aspects, the CScript interpreter is designed to quickly halt (fail-fast) and report errors instead of trying to continue with potentially corrupted or unexpected data. This ensures a seamless alignment with the validation requirements of modern web services, significantly enhancing readability and productivity in both documentation and implementation, as well as reducing the potential for bugs. + +## Keywords & Reserved Words +Here is a list of keywords (reserved words) in the CScript language. You cannot use any of the following words as identifiers in your scripts. Some keywords are reserved for future extensions and are not currently in use. + +| Description | Current Keyword (Reserved Word) | +|---------------------------|--------------------------------------------------| +| Variable Declaration | `var`; (`const`) | +| Conditional Flow Control | `if`; `else`; (`switch`; `case`; `default`) | +| Iterative Flow Control | `for`; `foreach`; `while`; (`do`) | +| Jump Control | `break`; (`continue`) | +| Membership Management | `in` | +| Function Declaration | `function`; `constraint`; `future`; `subroutine` | +| Function Data & Control | `return`; `target`; `caller` | +| Literals Value | `true`; `false`; `null`; `undefined` | +| Exception Management | `tryof`; `throw` | +| Class & Object Management | (`class`; `new`; `super`; `this`) | +| Script Modularization | (`import`) | + +## Data Types +Data types play a pivotal role in specifying the fundamental structure of values that serve as the foundational components for data manipulation within CScript. In the dynamically typed CScript language, data types are classified into two main categories: primitive immutable value types and composite reference types. + +Composite types include `#array` and `#object`, while the remaining types fall under the category of primitive types. Both primitive values and composite references of schema accessible from CScript are readonly and unmodifiable nodes. The following table lists CScript data types: + +| SN | Type Name | Example | +|----|--------------|--------------------------------------------| +| 1 | `#array` | `[1, 2, 3]`; `["item1", [2.5, 5.8]]`; `[]` | +| 2 | `#boolean` | `true`; `false` | +| 3 | `#double` | `10.5`; `20E-5`; `5E+5` | +| 4 | `#integer` | `10`; `20`; `100`; `500` | +| 5 | `#null` | `null` | +| 6 | `#object` | `{ k1: "text", k2: { "k11" : 10 } }`; `{}` | +| 7 | `#range` | `1..10`; `-10..-5`; `-10..`; `..100` | +| 8 | `#string` | `"any text"`; `""` | +| 9 | `#undefined` | `undefined` | +| 10 | `#void` | Used only for internal purposes | + +The `#void` type is reserved for internal operations, including initializing unassigned l-values (variables, properties, and array elements) to the default state, among other cases. To explicitly represent the absence of a value in your script, use the `undefined` or `null` literal. + +## Operators & Precedences +CScript operators are symbols that are used to perform operations on variables and values. The direct operation of any operator that requires a modifiable l-value including `++`, `--` or `=` will raise an exception for the readonly schema nodes. The following table lists the operators according to their precedences from the highest to the lowest: + +| SN | Category | Operator | +|----|-------------------------------|----------------------| +| 1 | Property Access & Parentheses | `.`; `[]`; `()` | +| 2 | Unary Minus & Logical Not | `-`; `!` | +| 3 | Postfix Increment/Decrement | `i++`; `i--` | +| 4 | Prefix Increment/Decrement | `++i`; `--i` | +| 5 | Arithmetic Multiplicative | `*`; `/` | +| 6 | Arithmetic Additive | `+`; `-` | +| 7 | Sequence Range | `..` | +| 8 | Relational Comparison | `>`; `<`; `>=`; `<=` | +| 9 | Equality Comparison | `==`; `!=` | +| 10 | Logical And (Short-Circuit) | `&&` | +| 11 | Logical Or (Short-Circuit) | `\|\|` | +| 12 | Assignment | `=` | + +## Function Types +Function types are essential for specifying the executable units that serve as the building-blocks of validation process within CScript. All function types can also accept variable number of arguments, specified by an ellipsis `...` after the last parameter name which is then bound to an array containing the remaining arguments. + +Additionally, all types of functions can be overloaded with varying numbers of fixed parameters, along with one that includes a variable argument parameter. A function name can be overloaded with only one variable argument definition, regardless of the number of required arguments preceding it. Fixed argument functions always take precedence or priority over variable argument functions when arguments match both definitions. Below are the various kinds of functions, each with distinct purposes, used in the CScript language: + +### Constraint Function +The constraint function defines conditions for the target JSON value. They assess whether the target JSON value satisfies the conditions specified by the functions. The function should return true if the conditions are met; otherwise, it should return false. Even if the function exits without returning any value, it is assumed that all conditions are met since any early return from the function usually implies that the conditions are not satisfied. + +Within the scope including nested scopes of a constraint function, the `target` keyword refers to the JSON value or node to which the constraint function is applied, and the `caller` keyword refers to the schema node that invokes this constraint function. The subsequent example illustrates various alternative forms of the definition of a constraint function named `example` with the main keyword `constraint`: +```js +constraint example(param1, param2, param3) { } +constraint function example(param1, param2, params...) { } +``` + +### Future Constraint Function +The future constraint function extends the utility of the constraint function by also considering receiver values. They ensure that the validations are deferred until the receivers of the schema have received their anticipated values, thus evaluating the specified conditions imposed by the functions at a delayed phase. The subsequent example illustrates various alternative forms of the definition of a future constraint function named `example` with the main keyword `future`: +```js +future example(param1, param2, param3) { } +future constraint example(param1, param2, param3) { } +future function example(param1, param2, param3) { } +future constraint function example(param1, param2, params...) { } +``` + +### Subroutine Function +The subroutine function supports the constraint function by promoting code reusability, readability, and modularization. These functions serve as auxiliary units, enhancing the organization and maintainability of validation in CScript, and are not available in the schema context for invocation. Conversely, the constraint function, as well as the future function, are special functions available in the schema context, and are not invocable from the script context without the `target` and `caller` information, thereby preventing any potential overloading conflicts between subroutine and constraint functions. The subsequent example illustrates various alternative forms of the definition of a subroutine function named `example` with the main keyword `subroutine`: +```js +subroutine example(param1, param2, param3) { } +subroutine function example(param1, param2, params...) { } +``` + +The CScript language provides a wide range of functions, data types, and programming constructs that can be used to implement diverse validation logic. This allows for the handling of complex validation requirements, both at the level of individual JSON values and groups of values received across different parts of the JSON document, ultimately ensuring the structural integrity of the entire JSON document. \ No newline at end of file diff --git a/doc/content/articles/datatypes.md b/doc/content/articles/datatypes.md index 0b34b71..4d87f25 100644 --- a/doc/content/articles/datatypes.md +++ b/doc/content/articles/datatypes.md @@ -122,7 +122,7 @@ The boolean data type is a binary or switch-based data type that only accepts tw ``` ### The Null Data Type -The null data type serves as a special constraint within JSON schemas, facilitating the controlled use of `null` in place of other JSON elements or values. Typically, it is combined with other data types to permit the use of `null` for specific JSON elements or values. This can set constraints for scenarios in which an array without any elements and an object without any properties can either have `null` or only be allowed to be empty. +The null data type serves as a special constraint within JSchema documents, facilitating the controlled use of `null` in place of other JSON elements or values. Typically, it is combined with other data types to permit the use of `null` for specific JSON elements or values. This can set constraints for scenarios in which an array without any elements and an object without any properties can either have `null` or only be allowed to be empty. Additionally, the `@nonempty` constraint functions can be employed to further control the use of empty values within a JSON document. To specify the null type in the schema, use the following syntax: ```html diff --git a/doc/content/articles/datetime.md b/doc/content/articles/datetime.md index 5ab455e..5b6a07c 100644 --- a/doc/content/articles/datetime.md +++ b/doc/content/articles/datetime.md @@ -1,7 +1,7 @@ +++ title = 'Date and Time' date = 2023-10-08T09:38:53+06:00 -weight = 8 +weight = 9 +++ # Date and Time Patterns @@ -56,4 +56,4 @@ The pattern components listed above can be combined to create comprehensive and The first pattern in the table above adheres to the ISO 8601 date format and is used to validate the `#date` data type within the schema. The second pattern in the table follows the ISO 8601 format for date and time, validating the `#time` data type in the schema. Instead of explicitly specifying these patterns in the `@date` or `@time` functions, a more concise approach is to directly utilize the `#date` or `#time` type within the schema. Detailed explanations regarding the date and time format of the ISO 8601 standard are available in this [document](https://www.iso.org/iso-8601-date-and-time-format.html). -When the AM/PM designator is included in the date and time pattern, the presence of any hour format specifier indicates that the time is in the 12-hour clock format. Conversely, when the AM/PM designator is omitted, the presence of any hour format specifier indicates that the time is in the 24-hour clock format. +When the AM/PM designator is included in the date and time pattern, the presence of any hour format specifier indicates that the time is in the 12-hour clock format. Conversely, when the AM/PM designator is omitted, the presence of any hour format specifier indicates that the time is in the 24-hour clock format. \ No newline at end of file diff --git a/doc/content/articles/directives.md b/doc/content/articles/directives.md index 8e9253f..47d9ffc 100644 --- a/doc/content/articles/directives.md +++ b/doc/content/articles/directives.md @@ -9,7 +9,7 @@ pre code { font-size: 1.1em; } # Validation Directives -Directives serve as special instructions or commands for the Schema and JSON parsers, interpreters, and validators. They are used to control various aspects of the validation process or to provide metadata for documentation. Additionally, they offer crucial information about Schema and JSON and provide custom validation functions to meet specific Schema validation requirements. +Directives serve as special instructions or commands for the JSchema parsers, interpreters, and validators. They are used to control various aspects of the validation process or to provide metadata for documentation. Additionally, they offer crucial information about schema and JSON, as well as essential customization of the validation procedure to meet specific requirements. ## Title Directive Within a schema, the title directive is used to provide a name, label, or a brief intent of the schema for which it is written. Besides, the title directive is optional and additional description can be supplied as multiple comments inside the schema document to provide more detail. @@ -20,15 +20,15 @@ However, this directive is only used for documentation purposes and does not hav ``` ## Version Directive -In a schema, the version directive is used to provide a version number of the schema which helps to keep track of updates. Although optional, the version directive is useful for documentation purposes and does not affect the validation process. The version directive can be represented using the following notation example: -```stylus -%version: 2023.09.11.01 +In a schema, the version directive is used to provide a version label of the schema document which helps to keep track of updates. Although optional, the version directive is useful for documentation purposes and does not affect the validation process. The version directive can be represented using the following notation example: +```js +%version: "2.0.0-beta1" ``` -## Include Directive -Include directive enables the addition or inclusion of a class, as defined by object-oriented programming, to a schema along with a set of methods that have specific signatures for performing custom validations. This feature extends the built-in validation capabilities of the schema. The example below illustrates how to utilize the include directive in Java language: +## Import Directive +Import directive enables the addition or inclusion of a class, as defined by object-oriented programming, to a schema along with a set of methods that have specific signatures for performing custom validations. This feature extends the built-in validation capabilities of the schema. The example below illustrates how to utilize the import directive in Java language: ```js -%include: com.relogiclabs.json.schema.external.ExternalFunctions +%import: com.relogiclabs.jschema.test.external.ExternalFunctions ``` ## Pragma Directive @@ -67,7 +67,7 @@ The `IgnoreObjectPropertyOrder` pragma directive provides a means to enforce a s ``` ## Definition / Define Directive -This feature in JSON schemas allows you to define a name for a schema component or fragment, which can be referenced from various parts of your schema. This means that if you encounter similar validation requirements in different sections of your schema, you can conveniently refer to the named schema component instead of duplicating the same validation rules. For more information about the schema component syntax and format, please refer to the documentation [here](/JSchema-Java/articles/components). Here is a simple example of how to use this directive: +This feature in JSchema allows you to define a name for a schema component or fragment, which can be referenced from various parts of your schema. This means that if you encounter similar validation requirements in different sections of your schema, you can conveniently refer to the named schema component instead of duplicating the same validation rules. For more information about the schema component syntax and format, please refer to the documentation [here](/JSchema-Java/articles/components). Here is a simple example of how to use this directive: ```js %define $product: { "id": @length(2, 10) @regex("[a-z][a-z0-9]+") #string, @@ -94,4 +94,17 @@ However, if there are no other directives used in the document, the entire docum "registeredAt": #time } } +``` + +## Script Directive +The script directive enables the inclusion of CScript code into a JSchema document, providing the flexibility to define custom validation functions directly within the schema document. These validation functions can accept any number of nodes across the JSON tree as parameters, enabling comprehensive processing and validation to ensure the data integrity of the entire JSON tree. For more information about CScript syntax and format, please refer to the documentation [here](/JSchema-Java/articles/cscript). The following is a simple example of how to use this directive: +```js +%script: { + constraint function checkAccess(role) { + if(role[0] == "user" && target > 5) return fail( + "ERRACCESS01", "Data access incompatible with 'user' role", + expected("an access at most 5 for 'user' role"), + actual("found access " + target + " which is greater than 5")); + } +} ``` \ No newline at end of file diff --git a/doc/content/articles/introduction.md b/doc/content/articles/introduction.md index fa0f415..779664a 100644 --- a/doc/content/articles/introduction.md +++ b/doc/content/articles/introduction.md @@ -5,9 +5,9 @@ weight = 1 +++ # Introduction -The New JSON Schema prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements. +JSchema, a new JSON Schema, prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements. -JSON, short for JavaScript Object Notation, is one of the most widely used data exchange formats that are both user-friendly and machine-readable. New JSON Schema is a practical tool for defining and validating the structure of JSON documents. The following guides offer comprehensive details about the New JSON Schema. This document provides a list of links, each corresponding to a specific detail document available in this project. +JSON, short for JavaScript Object Notation, is one of the most widely used data exchange formats that are both user-friendly and machine-readable. JSchema is a practical tool for defining and validating the structure of JSON documents. The following guides provide comprehensive details about the JSchema.
* [Getting Started & Installation](/JSchema-Java/articles/quickstart) @@ -16,9 +16,10 @@ JSON, short for JavaScript Object Notation, is one of the most widely used data * [Schema Specification & Grammar](/JSchema-Java/articles/specification) * [Data Types & Validation](/JSchema-Java/articles/datatypes) * [Functions & Validation](/JSchema-Java/articles/functions) + * [JSchema CScript & Validation](/JSchema-Java/articles/cscript) * [Date & Time Patterns](/JSchema-Java/articles/datetime) * [Defining Schema Components](/JSchema-Java/articles/components) * [Build from Source Code](/JSchema-Java/articles/sourcebuild) * [API Reference Documentation](/JSchema-Java/api/index.html) * [GitHub Source Code Repository](https://github.com/relogiclabs/JSchema-Java) -
+
\ No newline at end of file diff --git a/doc/content/articles/quickstart.md b/doc/content/articles/quickstart.md index d117abb..b85dddf 100644 --- a/doc/content/articles/quickstart.md +++ b/doc/content/articles/quickstart.md @@ -5,15 +5,15 @@ weight = 2 +++ # Getting Started -This guide will walk you through the essential steps to quickly get up and running with the new JSON Schema library. It is also assumed a modest familiarity with the Java language, Java SDK, and Java command-line interface, including basic familiarity with Maven packages. +This guide will walk you through the essential steps to quickly get up and running with the JSchema library. It is also assumed a modest familiarity with the Java language, Java SDK, and Java command-line interface, including basic familiarity with Maven packages. ## Maven Library Package -To get started, launch your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code) and open the Java project where you intend to include this library package. If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in Maven project, navigate to the Maven `pom.xml` file and locate the section named `` and add the following XML snippet within the section of the file, replacing `1.x.x` with either the latest version or your preferred version: +To get started, launch your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code) and open the Java project where you intend to include this library package. If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in Maven project, navigate to the Maven `pom.xml` file and locate the section named `` and add the following XML snippet within the section of the file, replacing `2.x.x` with either the latest version or your preferred version: ```xml com.relogiclabs.json - relogiclabs-json-schema - 1.x.x + relogiclabs-jschema + 2.x.x ``` For additional information regarding this library package, you can visit the Maven repository page of this library [here](https://central.sonatype.com/artifact/com.relogiclabs.json/relogiclabs-json-schema), and files are also available [here](https://repo1.maven.org/maven2/com/relogiclabs/json/relogiclabs-json-schema/). @@ -21,14 +21,14 @@ For additional information regarding this library package, you can visit the Mav ## Write a Sample to Test With all the necessary components in place, you are now ready to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a Java class featuring a method designed for validating a sample JSON based on a provided schema. If you are working with Java 17 or above, you can enhance the code further by utilizing new language features. ```java -import com.relogiclabs.json.schema.JsonSchema; +import com.relogiclabs.jschema.JsonSchema; public class SampleSchema { public boolean checkIsValid() { var schema = """ %title: "User Profile Response" - %version: 1.0.0 + %version: "1.0.0-basic" %schema: { "user": { @@ -143,23 +143,21 @@ try { ``` The following presents the printed stack trace for the preceding example. It's important to note that when using `JsonAssert`, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: ```json -com.relogiclabs.json.schema.exception.JsonSchemaException: DTYP04: Data type mismatch +com.relogiclabs.jschema.exception.JsonSchemaException: DTYP04: Data type mismatch Expected (Schema Line: 6:31): data type #integer Actual (Json Line: 3:14): found #string inferred by "not number" - at com.relogiclabs.json.schema.tree.ExceptionRegistry.failWith(ExceptionRegistry.java:31) - at com.relogiclabs.json.schema.type.JNode.failWith(JNode.java:73) - at com.relogiclabs.json.schema.type.JValidator.matchDataType(JValidator.java:87) - at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:76) - at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57) - at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:71) - at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57) - at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:71) - at com.relogiclabs.json.schema.type.JRoot.match(JRoot.java:50) - at com.relogiclabs.json.schema.tree.SchemaTree.match(SchemaTree.java:33) - at com.relogiclabs.json.schema.JsonAssert.isValid(JsonAssert.java:61) - at com.relogiclabs.json.schema.JsonAssert.isValid(JsonAssert.java:72) - at org.example.SampleSchema.checkIsValid(SampleSchema.java:64) - at org.example.Main.main(Main.java:5) + at com.relogiclabs.jschema.node.JValidator.matchDataType(JValidator.java:87) + at com.relogiclabs.jschema.node.JValidator.match(JValidator.java:76) + at com.relogiclabs.jschema.node.JObject.match(JObject.java:56) + at com.relogiclabs.jschema.node.JValidator.match(JValidator.java:71) + at com.relogiclabs.jschema.node.JObject.match(JObject.java:56) + at com.relogiclabs.jschema.node.JValidator.match(JValidator.java:71) + at com.relogiclabs.jschema.node.JRoot.match(JRoot.java:52) + at com.relogiclabs.jschema.tree.SchemaTree.match(SchemaTree.java:38) + at com.relogiclabs.jschema.JsonAssert.isValid(JsonAssert.java:61) + at com.relogiclabs.jschema.JsonAssert.isValid(JsonAssert.java:72) + at com.example.SampleSchema.checkIsValid(SampleSchema.java:68) + at com.example.Main.main(Main.java:5) ``` -For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JSchema-Java/api/index.html). \ No newline at end of file +Similar to the above illustration, there are a lot of test cases with various types of examples available in the source code repository [here](https://github.com/relogiclabs/JSchema-Java/tree/master/src/test/java/com/relogiclabs/jschema/test). \ No newline at end of file diff --git a/doc/content/articles/sourcebuild.md b/doc/content/articles/sourcebuild.md index b90d62a..6d7eca2 100644 --- a/doc/content/articles/sourcebuild.md +++ b/doc/content/articles/sourcebuild.md @@ -1,18 +1,18 @@ +++ title = 'Source Build' date = 2023-12-04T09:38:53+06:00 -weight = 10 +weight = 11 +++ # Build from Source Code -This comprehensive guide illustrates the procedures for retrieving source code from a GitHub repository, compiling the project source code into a library, and seamlessly integrating the compiled library into your project. It is essential to have a foundational understanding of the Java language, as well as a modest level of familiarity with the Java SDK and command-line interface. Some basic knowledge of how to work with Maven packages would be helpful. +This comprehensive guide illustrates the procedures for retrieving source code from a GitHub repository, compiling the project source code into a library, and seamlessly integrating the compiled library into your project. It is essential to have a foundational understanding of the Java language, as well as a modest level of familiarity with the Java SDK and command-line interface. Furthermore, some basic knowledge of how to work with Maven packages would be helpful. ## Build the Library To get started, clone the project from the following URL using your preferred Git client (command line or GUI). You can open a terminal and enter the following Git clone command as shown below: ```shell git clone https://github.com/relogiclabs/JSchema-Java.git ``` -Next, navigate to the project root directory of the `JSchema-Java` that you just cloned. Inside the directory, you should find a `pom.xml` file. This file contains the project configuration and dependencies required to build the library. Use the `cd` command to enter the project root directory and execute the following Maven command to build the Json Schema library: +Next, navigate to the project root directory of the `JSchema-Java` that you just cloned. Inside the directory, you should find a `pom.xml` file. This file contains the project configuration and dependencies required to build the library. Use the `cd` command to enter the project root directory and execute the following Maven command to build the JSchema library: ```shell mvn clean install @@ -20,26 +20,26 @@ mvn clean install Maven will resolve the library's dependencies, compile the code, and create a jar file which will be installed in the local Maven repository. ## Add the Library to Your Project -To integrate the library into your project, open it in your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code). If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in a Maven project, navigate to the Maven `pom.xml` file and locate the section named `` and add the following XML snippet within the section of the file, replacing `1.x.x` with the version you have built: +To integrate the library into your project, open it in your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code). If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in a Maven project, navigate to the Maven `pom.xml` file and locate the section named `` and add the following XML snippet within the section of the file, replacing `2.x.x` with the version you have built: ```xml com.relogiclabs.json - relogiclabs-json-schema - 1.x.x + relogiclabs-jschema + 2.x.x ``` ## Write a Sample to Test With all the necessary components in place, you are now ready to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a Java class featuring a method designed for validating a sample JSON based on a provided schema. If you are working with Java 17 or above, you can enhance the code further by utilizing new language features. ```java -import com.relogiclabs.json.schema.JsonSchema; +import com.relogiclabs.jschema.JsonSchema; public class SampleSchema { public boolean checkIsValid() { var schema = """ %title: "User Profile Response" - %version: 1.0.0 + %version: "1.0.0-basic" %schema: { "user": { @@ -154,23 +154,21 @@ try { ``` The following presents the printed stack trace for the preceding example. It's important to note that when using `JsonAssert`, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: ```json -com.relogiclabs.json.schema.exception.JsonSchemaException: DTYP04: Data type mismatch +com.relogiclabs.jschema.exception.JsonSchemaException: DTYP04: Data type mismatch Expected (Schema Line: 6:31): data type #integer Actual (Json Line: 3:14): found #string inferred by "not number" - at com.relogiclabs.json.schema.tree.ExceptionRegistry.failWith(ExceptionRegistry.java:31) - at com.relogiclabs.json.schema.type.JNode.failWith(JNode.java:73) - at com.relogiclabs.json.schema.type.JValidator.matchDataType(JValidator.java:87) - at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:76) - at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57) - at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:71) - at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57) - at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:71) - at com.relogiclabs.json.schema.type.JRoot.match(JRoot.java:50) - at com.relogiclabs.json.schema.tree.SchemaTree.match(SchemaTree.java:33) - at com.relogiclabs.json.schema.JsonAssert.isValid(JsonAssert.java:61) - at com.relogiclabs.json.schema.JsonAssert.isValid(JsonAssert.java:72) - at org.example.SampleSchema.checkIsValid(SampleSchema.java:64) - at org.example.Main.main(Main.java:5) + at com.relogiclabs.jschema.node.JValidator.matchDataType(JValidator.java:87) + at com.relogiclabs.jschema.node.JValidator.match(JValidator.java:76) + at com.relogiclabs.jschema.node.JObject.match(JObject.java:56) + at com.relogiclabs.jschema.node.JValidator.match(JValidator.java:71) + at com.relogiclabs.jschema.node.JObject.match(JObject.java:56) + at com.relogiclabs.jschema.node.JValidator.match(JValidator.java:71) + at com.relogiclabs.jschema.node.JRoot.match(JRoot.java:52) + at com.relogiclabs.jschema.tree.SchemaTree.match(SchemaTree.java:38) + at com.relogiclabs.jschema.JsonAssert.isValid(JsonAssert.java:61) + at com.relogiclabs.jschema.JsonAssert.isValid(JsonAssert.java:72) + at com.example.SampleSchema.checkIsValid(SampleSchema.java:68) + at com.example.Main.main(Main.java:5) ``` -For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JSchema-Java/api/index.html). \ No newline at end of file +Similar to the above illustration, there are a lot of test cases with various types of examples available in the source code repository [here](https://github.com/relogiclabs/JSchema-Java/tree/master/src/test/java/com/relogiclabs/jschema/test). \ No newline at end of file diff --git a/doc/content/articles/specification.md b/doc/content/articles/specification.md index 4e40018..2153a6e 100644 --- a/doc/content/articles/specification.md +++ b/doc/content/articles/specification.md @@ -9,10 +9,10 @@ pre code { font-size: 1.1em; } # Specification -New JSON Schema is a vocabulary that allows you to describe the structure and constraints of JSON documents. It provides a way to define rules for validating the data in a JSON document. With JSON Schema, you can ensure that your JSON data follows a specific format and adheres to certain rules. +JSchema is a vocabulary that allows you to describe the structure and constraints of JSON documents. It provides a way to define rules for validating the data in a JSON document. With JSchema, you can ensure that your JSON data follows a specific format and adheres to certain rules. ## Grammar -The New JSON Schema grammar is introduced through a notation similar to what is known as the McKeeman form grammar notation, which is a simplified version of the Backus-Naur form and Extended Backus–Naur form. This form minimizes the usage of complex structures of meta-characters, making the grammar highly readable and easy to understand without requiring extensive prior knowledge of grammar syntax. Moreover, inside the grammar whitespace defining rules are ignored to make it clear and concise. +JSchema grammar is introduced through a notation similar to what is known as the McKeeman form grammar notation, which is a simplified version of the Backus-Naur form and Extended Backus–Naur form. This form minimizes the usage of complex structures of meta-characters, making the grammar highly readable and easy to understand without requiring extensive prior knowledge of grammar syntax. Moreover, inside the grammar whitespace defining rules are ignored to make it clear and concise. ```html schema @@ -28,11 +28,7 @@ title-opt version-opt '' - '%version' ':' version-digits - -version-digits - digits - digits '.' version-digits + '%version' ':' string includes-opt '' @@ -276,4 +272,4 @@ one-to-nine '1' . '9' ``` -To explore more about McKeeman form grammar notation and standard JSON document grammar in McKeeman form notation, please visit [this page](https://www.json.org). The resource offers valuable information regarding JSON specification and implementations in different programming languages. +To explore more about McKeeman form grammar notation and standard JSON document grammar in McKeeman form notation, please visit [this page](https://www.json.org). The resource offers information regarding JSON specification and implementations in different programming languages. \ No newline at end of file diff --git a/doc/content/articles/validation.md b/doc/content/articles/validation.md index 78d0f96..ae5a6fc 100644 --- a/doc/content/articles/validation.md +++ b/doc/content/articles/validation.md @@ -16,7 +16,7 @@ Composite values in a JSON document act as containers. They can hold zero or mor Conversely, Non-composite values are the atomic data elements in a JSON document. They cannot contain other values within them. There are four types of primitive values supported by JSON specification: Strings, Numbers, Booleans, and Nulls. ## Validation Format -A JSON Schema ensures the correctness and consistency of JSON documents, and it also defines the structure and constraints that a JSON document must conform to. It specifies how both composite and non-composite values should be organized and validated the input document based on the rules specified in the schema document. Thus, a key element of JSON Schema is the validation rule syntax, which provides the required instructions for the validation process. A validation rule is typically expressed using the following notations: +JSchema provides essential utilities to ensure the correctness and consistency of JSON documents, while defining the structure and constraints that JSON documents must conform to. It specifies how both composite and non-composite values should be organized and validated the input document based on the rules specified in the schema document. Thus, a key element of JSchema is the validation rule syntax, which provides the required instructions for the validation process. A validation rule is typically expressed using the following notations: ```js 1. [Value] [Function-Set] [DataType-Set] [Receiver-Set] [Optional] 2. [Undefined] [Optional] @@ -72,7 +72,7 @@ Validation of the `Datatype-Set` is deemed successful if validation is successfu | 2 | `#integer* #array` | `[1, 3]`; `[2, 4, 6, 8, 10]` | `[10, 10.5, 1E-08]`; `10`; `null` | | 3 | `#string` | `"lorem"`; `"lorem ipsum"` | `100.5`; `["a", "b"]`; `null` | | 4 | `#string* #array` | `["lorem", "lorem ipsum"]` | `[10, "lorem"]`; `"lorem"`; `null` | -| 5 | `#integer #float` | `5`, `10.5`, `1000` | `1E-08`; `"lorem"`; `false`; `null` | +| 5 | `#integer #float` | `5`; `10.5`; `1000` | `1E-08`; `"lorem"`; `false`; `null` | | 6 | `#array #null` | `[10, 20, 30]`; `null` | `10`; `100.5`; `"lorem"` | | 7 | `#integer* #float* #array` | `[10, 10.5, 100]` | `[10, "lorem", false, null]` | @@ -86,4 +86,4 @@ The `Optional` marker, denoted as `?`, specifies that the presence of the target However, if the target value is present, the validation rule must succeed for the document to be considered valid and conform to the Schema. The absence of the `Optional` specifier requires the target JSON value to be present in the input JSON document for validation to succeed. -In instances where no validation rule (or no parts of the validation rule) is explicitly defined for a target input JSON value, the use of the undefined marker `!` signifies that any valid JSON value is acceptable for the target. This allows more flexibility in JSON data validation for specific cases. +In instances where no validation rule (or no parts of the validation rule) is explicitly defined for a target input JSON value, the use of the undefined marker `!` signifies that any valid JSON value is acceptable for the target. This allows more flexibility in JSON data validation for specific cases. \ No newline at end of file diff --git a/doc/hugo.toml b/doc/hugo.toml index c181665..d3700c4 100644 --- a/doc/hugo.toml +++ b/doc/hugo.toml @@ -1,6 +1,6 @@ baseURL = "https://relogiclabs.github.io/JSchema-Java" languageCode = "en-us" -title = "New Json Schema" +title = "JSchema" pygmentsCodeFences = true pygmentsCodefencesGuessSyntax = true diff --git a/doc/public/api/allclasses-index.html b/doc/public/api/allclasses-index.html index b543c08..3e3a386 100644 --- a/doc/public/api/allclasses-index.html +++ b/doc/public/api/allclasses-index.html @@ -1,11 +1,11 @@ - -All Classes and Interfaces (New Json Schema 1.12.0 API) + +All Classes and Interfaces (JSchema - New JSON Schema 2.0.0 API) - + @@ -61,202 +61,248 @@

All Classes and Interfaces<
Class
Description
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- -
 
- + +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+
 
- + +
 
+ +
 
+ +
 
+ +
 
+
 
- +
 
- +
 
- +
 
- -
 
-
IndexMap<TK,TV extends Keyable<TK>>
+ +
 
+
 
- -
 
- +
IndexMap<TK,TV extends Keyable<TK>>
+
 
+
 
- +
 
- +
 
- +
 
- + +
 
+ +
 
+
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
The class provides assertion functionalities to validate JSON documents against - a Schema or JSON.
+ a JSchema or JSON document.
- +
 
- +
 
- +
 
- +
-
JsonSchema provides Schema validation functionalities for JSON document.
+
JsonSchema provides JSchema validation functionalities for JSON document.
- +
 
- +
 
- +
 
- -
 
- + +
 
+
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- +
 
- + +
 
+ +
 
+ +
 
+ +
 
+
 
- +
 
- -
 
- -
 
- +
 
- +
 
- + +
 
+ +
 
+
 
- +
 
- +
 
- -
 
- + +
 
+
 
- -
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
diff --git a/doc/public/api/allpackages-index.html b/doc/public/api/allpackages-index.html index 6dba137..f39bd41 100644 --- a/doc/public/api/allpackages-index.html +++ b/doc/public/api/allpackages-index.html @@ -1,11 +1,11 @@ - -All Packages (New Json Schema 1.12.0 API) + +All Packages (JSchema - New JSON Schema 2.0.0 API) - + @@ -55,29 +55,31 @@

All Packages

diff --git a/doc/public/api/com/relogiclabs/json/schema/JsonAssert.html b/doc/public/api/com/relogiclabs/jschema/JsonAssert.html similarity index 82% rename from doc/public/api/com/relogiclabs/json/schema/JsonAssert.html rename to doc/public/api/com/relogiclabs/jschema/JsonAssert.html index e01d5ac..7907cbf 100644 --- a/doc/public/api/com/relogiclabs/json/schema/JsonAssert.html +++ b/doc/public/api/com/relogiclabs/jschema/JsonAssert.html @@ -1,26 +1,26 @@ - -JsonAssert (New Json Schema 1.12.0 API) + +JsonAssert (JSchema - New JSON Schema 2.0.0 API) - - + + - - - - - - + + + + + +