https://github.com/disaverio/ucast
Kotlin library to build, validate, normalize and (de)serialize UCAST expressions.
https://github.com/disaverio/ucast
boolean-expressions dsl json kotlin opa ucast
Last synced: 25 days ago
JSON representation
Kotlin library to build, validate, normalize and (de)serialize UCAST expressions.
- Host: GitHub
- URL: https://github.com/disaverio/ucast
- Owner: disaverio
- License: apache-2.0
- Created: 2026-05-04T17:01:15.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-25T17:48:55.000Z (about 1 month ago)
- Last Synced: 2026-05-25T19:31:06.354Z (about 1 month ago)
- Topics: boolean-expressions, dsl, json, kotlin, opa, ucast
- Language: Kotlin
- Homepage: https://central.sonatype.com/artifact/dev.disaverio/ucast
- Size: 56.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ucast
[](https://opensource.org/licenses/Apache-2.0)
[](https://central.sonatype.com/artifact/dev.disaverio/ucast)
A Kotlin library that models, builds, serializes and normalizes
[UCAST](https://github.com/stalniy/ucast) boolean expressions — the JSON-based format
also adopted in OPA - Open Policy Agent, [see docs](https://www.openpolicyagent.org/docs/filtering/ucast-syntax).
`ucast-lib` provides:
- A type-safe model of UCAST expressions (`CompoundExpression`, `FieldExpression`).
- A Kotlin DSL for building expressions ergonomically.
- JSON serialization in two dialects: **expanded** and **concise**.
- A normalization primitive that converts an arbitrary expression into [Disjunctive Normal Form](https://en.wikipedia.org/wiki/Disjunctive_normal_form).
## Install
Choose the version that matches the Jackson major version used in your project.
| Your Jackson dependency | `ucast` version to use |
|------------------------|------------------------|
| `com.fasterxml.jackson` (Jackson 2.x) | `0.0.0` |
| `tools.jackson` (Jackson 3.x) | `1.0.0` |
### Maven
**Jackson 3.x projects (`tools.jackson`)**
```xml
dev.disaverio
ucast
1.0.0
```
**Jackson 2.x projects (`com.fasterxml.jackson`)**
```xml
dev.disaverio
ucast
0.0.0
```
### Gradle (Kotlin DSL)
**Jackson 3.x projects (`tools.jackson`)**
```kotlin
dependencies {
implementation("dev.disaverio:ucast:1.0.0")
}
```
**Jackson 2.x projects (`com.fasterxml.jackson`)**
```kotlin
dependencies {
implementation("dev.disaverio:ucast:0.0.0")
}
```
## Quick example
```kotlin
import dev.disaverio.ucast.dsl.*
val expr = and {
"age" gte 18
or {
"role" eq "admin"
"department" `in` listOf("eng", "sec")
}
not {
"status" eq "banned"
}
}
```
## Grammar
The two supported syntaxes are documented under [`src/main/resources/definitions`](src/main/resources/definitions) as resources:
- [Expanded grammar](src/main/resources/definitions/ucast-expanded-grammar.txt) — JSON Schema available in [`ucast-grammar.json`](src/main/resources/definitions/ucast-grammar.json).
- [Concise grammar](src/main/resources/definitions/ucast-concise-grammar.txt) — sugared form with implicit-AND objects and field shorthand.
Note: the concise dialect is currently emit-only; deserialization supports the expanded form only.
## Build
Requires JDK 17+.
```bash
mvn clean test
```
## License
Apache License 2.0 — see [LICENSE](LICENSE).