Kotlin-jsonq : a library to query over json data
Published in
1 min readMay 27, 2018
kotlin-jsonq is a kotlin library to query over JSON data.
Getting started,
Adding library,
allprojects {
repositories {
... maven { url "https://jitpack.io" }
}
}dependencies {
implementation 'ninja.sakib:kotlin-jsonq:v0.2'
}
Initialization,
val inputStream = Thread.currentThread().contextClassLoader.getResourceAsStream("data.json")
val jsonq = JSONQ(inputStream)
find(path: String): JsonValue
- finds a json object from the specified json pathfrom(path: String): JsonArray
- finds a json array to do querywhereEq(key: String, value: Any): JsonArray
- returns json value if there any object equals to value.whereGt(key: String, value: Any): JsonArray
- returns json value if there any object greater than value.whereGe(key: String, value: Any): JsonArray
- returns json value if there any object greater than equals to value.whereLt(key: String, value: Any): JsonArray
- returns json value if there any object less than value.whereLe(key: String, value: Any): JsonArray
- returns json value if there any object less than equals to value.hasSuffix(key: String, value: Any): JsonArray
- returns json value if there any object has suffix to value.hasPrefix(key: String, value: Any): JsonArray
- returns json value if there any object has prefix to value.contains(key: String, value: Any): JsonArray
- returns json value if there any object contains value.sum(key: String): Double
- returns sum of the key.min(key: String): JsonValue
- returns minimum value of the key.max(key: String): JsonValue
- returns maximum value of the key.avg(key: String): Double
- returns average value of the key.
*** Put key empty if array doesn’t contain json object.
Though the library isn’t compelete yet. So if you are interested feel free to contribute.