Skip to content

Commit 22c775d

Browse files
committed
Update project documentations
1 parent e40b325 commit 22c775d

File tree

350 files changed

+25309
-14275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

350 files changed

+25309
-14275
lines changed

README.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# A New JSON Schema
2-
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).
1+
# JSchema - The New JSON Schema
2+
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 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).
33

44
## Design Goals
55
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
1010
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.
1111
```cpp
1212
%title: "User Profile Response"
13-
%version: 1.0.0
13+
%version: "1.0.0-basic"
1414
%schema:
1515
{
1616
"user": {
@@ -63,11 +63,10 @@ In the above example, two types of constraints are used: constraint functions (a
6363
}
6464
```
6565
## Extended Example
66-
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).
66+
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).
6767
```cpp
6868
%title: "Extended User Profile Dashboard API Response"
69-
%version: 2.0.0
70-
%include: com.relogiclabs.json.schema.external.ExternalFunctions
69+
%version: "2.0.0-extended"
7170

7271
%pragma DateDataTypeFormat: "DD-MM-YYYY"
7372
%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
133132
"isCloudy": #boolean
134133
}
135134
}
135+
136+
%script: {
137+
constraint function checkAccess(role) {
138+
// Receiver &role received only one value
139+
// 'target' keyword refers to the target JSON value
140+
if(role[0] == "user" && target > 5) return fail(
141+
"ERRACCESS01", "Data access incompatible with 'user' role",
142+
expected("an access at most 5 for 'user' role"),
143+
actual("found access " + target + " which is greater than 5"));
144+
}
145+
}
136146
```
137147
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.
138148
```json

doc/content/_index.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ date = 2023-10-08T09:38:53+06:00
44
+++
55

66
# Introduction
7-
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.
7+
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.
88

9-
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.
9+
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.
1010
<br/>
1111

1212
* <font size="4">[Getting Started & Installation](/JSchema-Java/articles/quickstart)</font>
@@ -15,9 +15,10 @@ JSON, short for JavaScript Object Notation, is one of the most widely used data
1515
* <font size="4">[Schema Specification & Grammar](/JSchema-Java/articles/specification)</font>
1616
* <font size="4">[Data Types & Validation](/JSchema-Java/articles/datatypes)</font>
1717
* <font size="4">[Functions & Validation](/JSchema-Java/articles/functions)</font>
18+
* <font size="4">[JSchema CScript & Validation](/JSchema-Java/articles/cscript)</font>
1819
* <font size="4">[Date & Time Patterns](/JSchema-Java/articles/datetime)</font>
1920
* <font size="4">[Defining Schema Components](/JSchema-Java/articles/components)</font>
2021
* <font size="4">[Build from Source Code](/JSchema-Java/articles/sourcebuild)</font>
2122
* <font size="4">[API Reference Documentation](/JSchema-Java/api/index.html)</font>
2223
* <font size="4">[GitHub Source Code Repository](https://github.com/relogiclabs/JSchema-Java)</font>
23-
<br/>
24+
<br/>

doc/content/articles/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ title = 'Articles'
33
date = 2023-10-08T09:38:53+06:00
44
+++
55

6-
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.
6+
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.

doc/content/articles/components.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
+++
22
title = 'Components'
33
date = 2023-12-15T09:38:53+06:00
4-
weight = 9
4+
weight = 10
55
+++
66

77
# Schema Components
@@ -45,19 +45,19 @@ By defining a reusable schema component with a clear and descriptive name, one c
4545
"id": 1,
4646
"title": "Getting Started",
4747
"preview": "This guide will show you through the essential steps to quickly...",
48-
"tags": ["JSON", "Json Schema", "Quick Start"]
48+
"tags": ["JSON", "JSchema", "Quick Start"]
4949
},
5050
{
5151
"id": 2,
5252
"title": "Validation Syntax",
5353
"preview": "A JSON document is a structured data format used for the exchange...",
54-
"tags": ["JSON", "Json Schema", "Validation Syntax"]
54+
"tags": ["JSON", "JSchema", "Validation Syntax"]
5555
},
5656
{
5757
"id": 3,
5858
"title": "Constraint Functions",
5959
"preview": "This document serves as a brief overview, providing key insights into...",
60-
"tags": ["JSON", "Json Schema", "Constraint Functions"]
60+
"tags": ["JSON", "JSchema", "Constraint Functions"]
6161
}
6262
]
6363
```

doc/content/articles/cscript.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
+++
2+
title = 'CScript DSL'
3+
date = 2024-01-25T09:38:53+06:00
4+
weight = 8
5+
+++
6+
7+
# CScript Domain-Specific Language
8+
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.
9+
10+
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.
11+
12+
## Keywords & Reserved Words
13+
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.
14+
15+
| Description | Current Keyword (Reserved Word) |
16+
|---------------------------|--------------------------------------------------|
17+
| Variable Declaration | `var`; (`const`) |
18+
| Conditional Flow Control | `if`; `else`; (`switch`; `case`; `default`) |
19+
| Iterative Flow Control | `for`; `foreach`; `while`; (`do`) |
20+
| Jump Control | `break`; (`continue`) |
21+
| Membership Management | `in` |
22+
| Function Declaration | `function`; `constraint`; `future`; `subroutine` |
23+
| Function Data & Control | `return`; `target`; `caller` |
24+
| Literals Value | `true`; `false`; `null`; `undefined` |
25+
| Exception Management | `tryof`; `throw` |
26+
| Class & Object Management | (`class`; `new`; `super`; `this`) |
27+
| Script Modularization | (`import`) |
28+
29+
## Data Types
30+
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.
31+
32+
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:
33+
34+
| SN | Type Name | Example |
35+
|----|--------------|--------------------------------------------|
36+
| 1 | `#array` | `[1, 2, 3]`; `["item1", [2.5, 5.8]]`; `[]` |
37+
| 2 | `#boolean` | `true`; `false` |
38+
| 3 | `#double` | `10.5`; `20E-5`; `5E+5` |
39+
| 4 | `#integer` | `10`; `20`; `100`; `500` |
40+
| 5 | `#null` | `null` |
41+
| 6 | `#object` | `{ k1: "text", k2: { "k11" : 10 } }`; `{}` |
42+
| 7 | `#range` | `1..10`; `-10..-5`; `-10..`; `..100` |
43+
| 8 | `#string` | `"any text"`; `""` |
44+
| 9 | `#undefined` | `undefined` |
45+
| 10 | `#void` | Used only for internal purposes |
46+
47+
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.
48+
49+
## Operators & Precedences
50+
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:
51+
52+
| SN | Category | Operator |
53+
|----|-----------------------------|----------------------|
54+
| 1 | Member Access & Parentheses | `.`; `[]`; `()` |
55+
| 2 | Unary Minus & Logical Not | `-`; `!` |
56+
| 3 | Postfix Increment/Decrement | `i++`; `i--` |
57+
| 4 | Prefix Increment/Decrement | `++i`; `--i` |
58+
| 5 | Arithmetic Multiplicative | `*`; `/` |
59+
| 6 | Arithmetic Additive | `+`; `-` |
60+
| 7 | Sequence Range | `..` |
61+
| 8 | Relational Comparison | `>`; `<`; `>=`; `<=` |
62+
| 9 | Equality Comparison | `==`; `!=` |
63+
| 10 | Logical And (Short-Circuit) | `&&` |
64+
| 11 | Logical Or (Short-Circuit) | `\|\|` |
65+
| 12 | Assignment | `=` |
66+
67+
## Function Types
68+
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.
69+
70+
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:
71+
72+
### Constraint Function
73+
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.
74+
75+
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`:
76+
```js
77+
constraint example(param1, param2, param3) { }
78+
constraint function example(param1, param2, params...) { }
79+
```
80+
81+
### Future Constraint Function
82+
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`:
83+
```js
84+
future example(param1, param2, param3) { }
85+
future constraint example(param1, param2, param3) { }
86+
future function example(param1, param2, param3) { }
87+
future constraint function example(param1, param2, params...) { }
88+
```
89+
90+
### Subroutine Function
91+
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`:
92+
```js
93+
subroutine example(param1, param2, param3) { }
94+
subroutine function example(param1, param2, params...) { }
95+
```
96+
97+
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.

doc/content/articles/datatypes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The boolean data type is a binary or switch-based data type that only accepts tw
122122
```
123123

124124
### The Null Data Type
125-
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.
125+
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.
126126

127127
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:
128128
```html

0 commit comments

Comments
 (0)