Kotlin JSON Forms
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:
https://user-images.githubusercontent.com/6157866/179068902-a8e3da2e-2a00-4a30-8c92-596f2ded2d3d.mov
Supported Platforms/Features
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).
Installation
repositories {
mavenCentral()
}
// for plain JVM or Android projects
dependencies {
implementation("io.github.copper-leaf:json-forms-compose-material:0.7.0")
}
// 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:0.7.0")
}
}
val androidMain by getting {
dependencies {
// Forms using Material components for Compose Android
implementation("io.github.copper-leaf:json-forms-compose-material:0.7.0")
}
}
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:0.7.0")
}
}
}
}
Documentation
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.
License
Kotlin JSON Forms is licensed under the BSD 3-Clause License, see LICENSE.md.
References and Dependencies
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