Omnist Java (omnist-j) Guide & Quickstart¶
Welcome to omnist-j, the official Java implementation of the Omnist data-interchange specification.
1. The Omnist Mental Model¶
Omnist is a spec-first data interchange system based on a simple, uniform document graph (ยง2.1).
Key Concepts¶
- Document = Node | Value:
- A document is either a
Nodeor aValue(a scalar ornull). - Ordered Edge Lists (No Native Arrays):
- A
Nodeis simply an ordered list ofEdge(label, target)pairs. - Omnist has no separate array data structure: repeated edge labels represent arrays. For instance:
This represents a single
items: 10 items: 20Nodecontaining two edges with the label"items". - Lossless Multi-Format Interchange:
- Omnist Markup Language (OML) is the native human-readable text syntax for the Document model.
omnist-jprovides bidirectional codecs for JSON, YAML, TOML, and XML, preserving ordering and structural intent.- Formal Schema Algebra:
- Omnist Schema Definition (OSD) provides exact record type definitions, optionality, cardinalities (
[min,max]), and set-theoretic schema operations (satisfiability, compatibility, equivalence, normalization, pruning, extraction, and inference).
2. Worked Quickstart Example¶
Here is a complete end-to-end example demonstrating OML parsing, OSD schema validation, materialization, and multi-format conversion.
// 1. Parse OML document
String oml = """
name: "Alice"
created: "2024-01-01"
role: "Admin"
""";
Document doc = OmlReader.read(oml);
// 2. Define OSD Schema
String osd = """
record User {
"name": string,
"created": date,
"role" [0,1]: string,
}
root User
""";
Schema schema = OsdReader.read(osd);
// 3. Materialize String to Typed Date
Document materialized = Materializer.materialize(doc, schema);
assertNotNull(materialized);
// 4. Validate Materialized Document against Schema
ValidationResult valResult = Validator.validate(materialized, schema);
assertTrue(valResult.isValid());
// 5. Convert to Canonical JSON
String json = JsonCodec.write(materialized);
assertTrue(json.contains("\"Alice\""));
3. Overview of Core Operations¶
Reading & Writing Formats¶
- OML:
OmlReader.read(text)/OmlWriter.write(doc) - JSON:
JsonCodec.read(text)/JsonCodec.write(doc) - YAML:
YamlCodec.read(text)/YamlCodec.write(doc) - TOML:
TomlCodec.read(text)/TomlCodec.write(doc) - XML:
XmlCodec.read(text)/XmlCodec.write(doc)
Validation & Materialization¶
Validator.validate(doc, schema): Performs structural and type-checking against schema constraints, returning aValidationResult.Materializer.materialize(doc, schema): Coerces scalar values (e.g. ISO-8601 string toLocalDate/LocalDateTime) based on target schema types.
Schema Algebra (SchemaAlgebra)¶
compatibleWith(s1, s2): Checks if schemas1is forward-compatible with schemas2.equivalent(s1, s2): Verifies set-theoretic equivalence of two schemas.normalize(schema): Merges isomorphic records into a minimal canonical schema.prune(schema): Removes unreachable record definitions.extract(schema, fields): Projects a schema down to specified label paths.infer(samples): Infers an OSD schema from sample document instances.
4. Documentation Index¶
docs/01-api-reference.md: Complete Java API Reference for all public classes and methods.docs/02-cli-reference.md: Complete Command-Line Interface (CLI) Reference.workflow-playbook.md: Development & Spec Alignment Playbook.