Customizable JSON Schema-based forms for Kotlin and Compose
This project aims to reimplement JSON Forms in Kotlin for use in Compose-based applications. Rather than defining its own formats or standards, this repo adopts JSON for form configuration and layout of well-known or standardized formats. Form fields and validation is provided in JSON Schema format, and the way the form is laid out and displayed is through JSON Forms format format. Using JSON as as the form definition gives an easy, portable way to display and dynamically change forms in your application.
This repo aims to support all features of the original JSON Forms library, which is written in Javascript, as well as following similar architectural patterns. For all topic related to the JSON format itself, that library's documentation will be a valid reference for this library.
See the video below for an example form in action:
Untitled.mov
This project currently supports Android and Desktop targets with the json-forms-compose-material
artifact, which uses
json-kotlin-schema for schema validation.
JavaScript is also supported for Compose DOM (no Canvas implementation yet), using the json-forms-compose-bulma
artifact. This displays forms based on Bulma CSS for styling and class names. JS target uses
Ajv for schema validation (the same validator library used in the original
JSON Forms library).
repositories {
mavenCentral()
}
// for plain JVM or Android projects
dependencies {
implementation("io.github.copper-leaf:json-forms-compose-material:{{site.version}}")
}
// for multiplatform projects
kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
// Forms using Material components for Compose Desktop
implementation("io.github.copper-leaf:json-forms-compose-material:{{site.version}}")
}
}
val androidMain by getting {
dependencies {
// Forms using Material components for Compose Android
implementation("io.github.copper-leaf:json-forms-compose-material:{{site.version}}")
}
}
val commonMain by getting {
dependencies {
// Forms using HTML widgets for Compose Web DOM, using Bulma CSS framework for styling
implementation("io.github.copper-leaf:json-forms-compose-bulma:{{site.version}}")
}
}
}
}
See the website for detailed documentation and usage instructions.
The documentation site, and this library in general, is very much a POC at this point, and everything is subject to change without warning. But you can always find the most up-to-date usage in the example apps.
Kotlin JSON Forms is licensed under the BSD 3-Clause License, see LICENSE.md.
This project depends on the following libraries:
- json-kotlin-schema for providing JSON parsing and validation on JVM, which itself depends on many other Java or Kotlin JSON libraries by the same author
- Ajv for providing JSON parsing and validation on JS
- richtext-compose-multiplatform for rich text editor capabilities
- compose-code-editor for code editor capabilities