A simple Kotlin library to Query over Json Data.
A simple Kotlin library to Query over JSON Data
Gradle,
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
And
dependencies {
implementation 'ninja.sakib:kotlin-jsonq:v0.2'
}
Let's see a quick example:
val inputStream = Thread.currentThread().contextClassLoader.getResourceAsStream("data.json")
jsonq = JSONQ(inputStream)
val obj = jsonq.find("users.5.visits")
Result,
[
{
"name": "Sylhet",
"year": 2011
},
{
"name": "Cox's Bazar",
"year": 2012
},
{
"name": "Bandarbar",
"year": 2014
}
]
val res = jsonq.from("users.5.visits").whereEq("name", "Bandarbar")
Result,
[
{
"name": "Bandarbar",
"year": 2014
}
]
val res = jsonq.from("users").hasSuffix("name", "Sumi")
Result,
[
{
"id": 1,
"name": "Johura Akter Sumi",
"location": "Barisal"
}
]
val res = jsonq.from("users").whereGe("id", 3).whereEq("location", "Barisal").contains("name", "Is")
Result,
[
{
"id": 3,
"name": "Ariful Islam",
"location": "Barisal"
}
]
If you encounter any bugs or issues, feel free to open an issue at github.
Also, you can shoot me an email to mailto:[email protected] for hugs or bugs.
Nahid Bin Azhar for the original idea.
If you are interested to make the package better please send pull requests or create an issue so that others can fix. Read the contribution guide here