Kotlin JSON Query 🚀

A lightweight Kotlin library for querying and transforming JSON data using a fluent, composable API. ✨
Features 🛠️
- 🧭 Traverse nested paths, index and slice JSON arrays
- 🔎 Select and filter JSON object properties
- 📊 Aggregate data common functions
- 🧩 Compose queries fluently
- 📚 Naturally compatible with Kotlin Notebook
Get Started 🚀
implementation("io.github.lexa-diky:json-query:0.6.0")
Quick Examples 🚦
Path syntax cheatsheet
Querying Json data
val json = Json.parseToJsonElement(File().readText())
println(json.query { path() })
println(json.query { path()[].path() })
println(json.query { path() })
println(json.query())
println(json.query { path() })
println(json.query { path() })
println(json.query { path().filterT<String> { it.startsWith() } })
println(json.query { path()[].path() })
Typed query results with queryAs
You can use queryAs to directly convert the result of a query to a Kotlin type using kotlinx.serialization:
val names = json.queryAs<List<String>> { path("shelter.cats.name") }
val age = json.queryAs<Int> { path("shelter.cats.1.age") }
Modifying queried data
Performance
json-query-kt is designed to be efficient and fast, it beats standard kotlinx-serialization object mapping in most
cases, especially for large datasets and/or complex serialization logic.
