A Clojure(Script) library for declarative data description, validation, and coercion.
Schema is a Clojure and ClojureScript library for declarative data description and validation. It provides a lightweight way to define the expected shape of data—like nested maps, lists, or specific value types—and validate that data matches those expectations. It solves the problem of unclear data contracts in Clojure codebases, making functions easier to understand and debug.
Clojure and ClojureScript developers working on teams or projects where data shape clarity, API robustness, and maintainability are important. It's especially useful for those building services, APIs, or applications with complex data flows.
Developers choose Schema because it offers a simple, idiomatic way to document and validate data without the overhead of a full type system. Its seamless integration with Clojure, rich error messages, and powerful features like coercion and test data generation make it a practical tool for improving code quality.
Clojure(Script) library for declarative data description and validation
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Schemas are plain Clojure data structures that mirror your data, making them easy to read and write, as shown in examples like {:a {:b s/Str :c s/Int}}.
Validation failures provide descriptive, programmer-friendly errors that pinpoint exact issues, such as 'not (instance? java.lang.String :b)' for type mismatches.
Macros like s/defn allow annotating function arguments and return values with schemas, enabling optional runtime validation without disrupting code flow.
Schema can automatically transform input data, like converting JSON strings to keywords, using coercion matchers that simplify API handling.
Enabling validation adds computational cost at runtime, which can be significant in performance-critical paths, and requires careful management with features like s/validator.
Unlike full type systems, Schema does not provide static type checking; errors are only caught at runtime, which might delay bug detection.
Some utilities, such as data generation and partial datum completion, are labeled as experimental in the README, indicating they may be unstable or lack long-term support.