The JSON schema validation library that works with https://github.com/Kotlin/kotlinx.serialization
MIT License
Bot releases are hidden (Show)
🤔 No bugs at all?
https://github.com/OptimumCode/json-schema-validator/compare/0.0.11...0.0.12
Published by OptimumCode 7 months ago
$id
is not an absolute URI (PR: #88)Published by OptimumCode 8 months ago
🤔 No bugs at all?
Published by OptimumCode 8 months ago
Published by OptimumCode 8 months ago
Published by OptimumCode 8 months ago
🤔 No bugs at all?
Published by OptimumCode 9 months ago
Published by OptimumCode 10 months ago
🤔 No bugs at all?
Published by OptimumCode 10 months ago
No new features today 😢
Published by OptimumCode 10 months ago
🤔 No bugs at all?
Published by OptimumCode about 1 year ago
🤔 No bugs at all?
Published by OptimumCode about 1 year ago
This is the first release of the multiplatform JSON-schema-validator library.
Add library to your dependencies
implementation("io.github.optimumcode:json-schema-validator:0.0.1")
Create a schema and validate the JSON element you need
import io.github.optimumcode.json.schema.JsonSchema
import io.github.optimumcode.json.schema.ValidationError
import kotlinx.serialization.json.JsonElement
val key = "\$" // to use $ in multiline string
val schema = JsonSchema.fromDefinition(
"""
{
"${key}schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"positiveInteger": {
"type": "integer",
"minimum": 0
}
},
"properties": {
"size": { "${key}ref": "#/definitions/positiveInteger" }
}
}
""".trimIndent(),
)
val errors = mutableListOf<ValidationError>()
val elementToValidate: JsonElement = loadJsonToValidate()
val valid = schema.validate(elementToValidate, errors::add)
This library is in the early stage of development so more changes and features are on the way.
Some of them you can find in the README and opened issues.
If you have any questions/suggestions/problems, please, create an issue on GitHub and I will try to help you