DiCentra Weaver is a powerful, schema-driven transformation framework designed to map and process JSON data using a specialized expression language. Built with Kotlin Multiplatform, it provides a consistent transformation engine across JVM, Android, iOS, JS, and Wasm targets.
- Schema-Driven Transformations: Define your data mapping rules in a structured schema.
- Weaver Object Language (WOL): A rich expression language for dynamic data access and computation.
- Kotlin Multiplatform: Run the same transformation logic on any platform.
- Extensible Architecture: Easily add custom functions and plugins.
- High Performance: Efficiently handles complex JSON structures.
Add the dependency to your build.gradle.kts:
implementation("cloud.mallne.dicentra.weaver:core:1.0.0-SNAPSHOT")WOL is the core of Weaver's transformation capabilities. It comes in two flavors: Accessor WOL for path traversal and Computation WOL for logic and arithmetic.
Used to navigate JSON structures and interpolate values.
| Example | Description |
|---|---|
user.id |
Accesses the id field of the user object. |
items[0] |
Accesses the first element of the items array. |
{otherSchema.id} |
Interpolates a value from another schema. |
{#transform#} |
Calls a LimboObject (a named transformation). |
{##param##} |
Accesses a parameter passed to the transformation. |
{|#val#|i|} |
Coerces the result of {#val#} to an integer. |
Used for logic, arithmetic, and more complex transformations.
| Category | Examples |
|---|---|
| Arithmetic | 1 + 2, (10 * {price}) / 2, 5 % 2 |
| Logic | true && {isAdmin}, !{isBlocked}, (5 > 2) || false |
| Comparison | {age} >= 18, 'admin' == {role}, 5 != 10 |
| Ternary | {score} > 50 ? 'Pass' : 'Fail' |
| Elvis Operator | {name} ?: 'Anonymous' |
| Coercion | |{count}|s| (ToString), |'true'|b| (ToBoolean) |
| Functions | pow(2, 8), max({a}, {b}) |
val weaver = Weaver()
val schema = WeaverSchema(
key = "userProfile",
root = PropertyDeclaration(
content = "{#transformedUser#}"
),
transforms = listOf(
LimboObjectDeclaration(
name = "transformedUser",
// Define your transformation logic here
)
)
)
val engine = weaver.engine(schema)
val result = engine.execute<UserProfile>(inputJson)core: The main execution engine and schema model.tokenizer: ANTLR-based parser for the Weaver Object Language.
This project is licensed under the Apache License 2.0. See LICENSE for details.
Built with ❤️ by Mallne under the DiCentra umbrella