/ json

Kotlin-jsonq : a library to query over json data

kotlin-jsonq is a kotlin library to query over json data. It's all started with https://github.com/nahid/jsonq by Nahid Bin Azhar.

Getting started,

Adding library,

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}
dependencies {
    implementation 'ninja.sakib:kotlin-jsonq:v0.1'
}


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 path

  • from(path: String): JsonArray - finds a json array to do query

  • whereEq(key: String, value: Any): MutableList<Any> - returns json value if there any object equals to value.

  • whereGt(key: String, value: Any): MutableList<Any> - returns json value if there any object greater than value.

  • whereGe(key: String, value: Any): MutableList<Any> - returns json value if there any object greater than equals to value.

  • whereLt(key: String, value: Any): MutableList<Any> - returns json value if there any object less than value.

  • whereLe(key: String, value: Any): MutableList<Any> - returns json value if there any object less than equals to value.

  • hasSuffix(key: String, value: Any): MutableList<Any> - returns json value if there any object has suffix to value.

  • hasPrefix(key: String, value: Any): MutableList<Any> - returns json value if there any object has prefix to value.

  • contains(key: String, value: Any): MutableList<Any> - 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.

Library : https://github.com/s4kibs4mi/kotlin-jsonq