Expand description
§jlens-schema
Structural metadata for JSON documents, and the JSONata language service built on it.
- Inference.
Schema::inferderives aSchemafrom sample documents. It records types, required and optional fields, array items, number ranges, string formats, small enumerations and examples. - Configuration.
Schema::apply_overridesadds descriptions, labels, allowed values and hidden fields. Schemas convert to and from JSON Schema 2020-12 (Schema::to_json_schema,Schema::from_json_schema), so they can be versioned and edited by hand. - Language service.
LanguageServiceoffers completion, diagnostics (including references to fields that the schema does not have), hover and signature help for JSONata expressions. It types each part of an expression against the schema, following the evaluator’s rules for paths, filters and variables.
use jlens_schema::{LanguageService, Schema};
use serde_json::json;
let schema = Schema::infer(&[json!({
"customer": {"login": "123", "name": "XYZ"},
"items": [{"code": "1", "type": "apparel", "unitPrice": 10.0, "quantity": 2}]
})]);
let service = LanguageService::new(Some(schema));
// Fields of the items, inside a filter:
let text = "items[ty";
let labels: Vec<_> = service.complete(text, text.len()).items.into_iter()
.map(|i| i.label).collect();
assert_eq!(labels, ["type", "$type"]); // fields first, then matching functions
// A misspelt field is reported:
let warnings = service.diagnostics("customer.Login");
assert_eq!(warnings[0].code, "W0201");
assert!(warnings[0].message.contains("did you mean `login`"));Structs§
- Completion
Item - One completion suggestion.
- Completions
- Completion results.
- Field
- A field of an object shape.
- Function
Decl - A function the host application provides (a
jlens_core::HostFunction), declared to the language service so that it is completed and documented like a built-in function. - Hover
- Hover information.
- Language
Service - Completion, diagnostics, hover and signature help for expressions over a schema.
- Override
- Settings applied to the shape at one path (see
Schema::apply_overrides). - Schema
- Structural metadata about a family of JSON documents.
- Shape
- The structure of the values found at one place in the documents.
- Signature
Help - Help for the function call around the cursor.
Enums§
- Completion
Kind - What a completion item inserts.
- Json
Type - JSON types, as in JSON Schema (
integeris a number without a fractional part).