A simple Kotlin library to Query over Json Data.

Overview

kotlin-jsonq

License: CC0-1.0

A simple Kotlin library to Query over JSON Data

Installation

Gradle,

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

And

dependencies {
    implementation 'ninja.sakib:kotlin-jsonq:v0.2'
}

Usage

Let's see a quick example:

Sample data (data.json) ```json { "name": "products", "description": "Features product list", "vendor": { "name": "Computer Source BD", "email": "[email protected]", "website": "www.example.com" }, "users": [ { "id": 1, "name": "Johura Akter Sumi", "location": "Barisal" }, { "id": 2, "name": "Mehedi Hasan Nahid", "location": "Barisal" }, { "id": 3, "name": "Ariful Islam", "location": "Barishal" }, { "id": 4, "name": "Suhel Ahmed", "location": "Sylhet" }, { "id": 5, "name": "Firoz Serniabat", "location": "Gournodi" }, { "id": 5, "name": "Musa Jewel", "location": "Barishal", "visits": [ { "name": "Sylhet", "year": 2011 }, { "name": "Cox's Bazar", "year": 2012 }, { "name": "Bandarbar", "year": 2014 } ] } ], "products": [ { "id": 1, "city": "bsl", "name": "iPhone", "cat": 1, "price": 80000.5 }, { "id": 2, "city": null, "name": "macbook pro", "cat": 2, "price": 150000.1 }, { "id": 3, "city": "dhk", "name": "Redmi 3S Prime", "cat": 1, "price": 12000.1 }, { "id": 4, "city": null, "name": "Redmi 4X", "cat": 1, "price": 15000.1 }, { "id": 5, "city": "bsl", "name": "macbook air", "cat": 2, "price": 110000.00 }, { "id": 6, "city": null, "name": "macbook air 1", "cat": 2, "price": 81000.2 } ], "cities": [ { "id": 1, "name": "Barishal" }, { "id": 2, "name": "Noakhali" }, { "id": 3, "name": "Dhaka" }, { "id": 4, "name": "Rajshahi" }, { "id": 5, "name": "Chittagong" } ], "arr": [ 1, 2, 3, 4 ] } ```

Examples

  • Initialization,
val inputStream = Thread.currentThread().contextClassLoader.getResourceAsStream("data.json")
jsonq = JSONQ(inputStream)
  • find,
val obj = jsonq.find("users.5.visits")

Result,

[
  {
    "name": "Sylhet",
    "year": 2011
  },
  {
    "name": "Cox's Bazar",
    "year": 2012
  },
  {
    "name": "Bandarbar",
    "year": 2014
  }
]
  • whereEq,
val res = jsonq.from("users.5.visits").whereEq("name", "Bandarbar")

Result,

[
  {
    "name": "Bandarbar",
    "year": 2014
  }
]
  • hasSuffix,
val res = jsonq.from("users").hasSuffix("name", "Sumi")

Result,

[
  {
    "id": 1,
    "name": "Johura Akter Sumi",
    "location": "Barisal"
  }
]
  • Query Chaining
val res = jsonq.from("users").whereGe("id", 3).whereEq("location", "Barisal").contains("name", "Is")

Result,

[
  {
    "id": 3,
    "name": "Ariful Islam",
    "location": "Barisal"
  }
]

TODO

  • Add missing methods
  • Write full documentation with example

Bugs and Issues

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.

Special Mention

Nahid Bin Azhar for the original idea.

Contribution

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

See all contributors

You might also like...
An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

SquiDB is a SQLite database library for Android and iOS

Most ongoing development is currently taking place on the dev_4.0 branch. Click here to see the latest changes and try out the 4.0 beta. Introducing S

Sprinkles is a boiler-plate-reduction-library for dealing with databases in android applications

Sprinkles Sprinkles is a boiler-plate-reduction-library for dealing with databases in android applications. Some would call it a kind of ORM but I don

LiteGo is a Java-based asynchronous concurrency library. It has a smart executor, which can be freely set the maximum number of concurrent at same time , and the number of threads in waiting queue. It can also set waiting policies and overload strategies.

LiteGo:「迷你」的Android异步并发类库 LiteGo是一款基于Java语言的「异步并发类库」,它的核心是一枚「迷你」并发器,它可以自由地设置同一时段的最大「并发」数量,等待「排队」线程数量,还可以设置「排队策略」和「超载策略」。 LiteGo可以直接投入Runnable、Callable

Android library for auto generating SQL schema and Content provider

Android-AnnotatedSQL Android library for auto generating SQL schema and Content Provider by annotations. You will get a full-featured content provider

An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

Upsert DSL extension for Exposed, Kotlin SQL framework

Exposed Upsert Upsert DSL extension for Exposed, Kotlin SQL framework. Project bases on various solutions provided by community in the official "Expos

Samples demonstrating the usage of Realm-Kotlin SDK
Samples demonstrating the usage of Realm-Kotlin SDK

Realm-Kotlin Samples This repository contains a set of projects to help you learn about using Realm-Kotlin SDK Each sample demonstrates different use

Collection of Kotlin APIs/tools to make using Realm Mobile database easier

Compass Kotlin API and tools to make working with Realm easier Components Compass is designed to make working with Realm easier through collection of

Releases(v0.2)
Owner
Sakib Sami
Senior Software Engineer @twilio || Co-Founder @livemart || In love with @golang, @java, @erlang || Distributed Systems || Blockchain || IoT
Sakib Sami
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.

Thanks to JetBrains for support Kripton Persistence Library project! Kripton Persistence Library Kripton is a java library, for Android platform, that

xcesco 117 Nov 11, 2022
Core Data for Android

NexusData Core Data for Android NexusData is an object graph and persistence framework for Android. It allows for organizing and managing relational d

Dia Kharrat 71 Nov 11, 2022
Implementation of MVVM , Live Data and Room DAO for a robust materialistic design

Someday App to manage Weekly tasks Because who needs to remind you every week to do Samething Preview Main Layout Light Dark Main Layout (Expanded) Li

Anshul Saraf 2 May 13, 2021
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Andrew Grosner 4.9k Dec 30, 2022
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Andrew Grosner 4.9k Dec 30, 2022
A simple NoSQL client for Android. Meant as a document store using key/value pairs and some rudimentary querying. Useful for avoiding the hassle of SQL code.

SimpleNoSQL A simple NoSQL client for Android. If you ever wanted to just save some data but didn't really want to worry about where it was going to b

Colin Miller 389 Sep 25, 2022
ORMDroid is a simple ORM persistence framework for your Android applications.

ORMDroid is a simple ORM persistence framework for your Android applications, providing an easy to use, almost-zero-config way to handle model persist

Ross Bamford 87 Nov 10, 2022
A simple ToDo app to demonstrate the use of Realm Database in android to perform some basic CRUD operations like Create, Update and Delete.

Creating a Realm Model Class @RealmClass open class Note() : RealmModel { @PrimaryKey var id: String = "" @Required var title: String

Joel Kanyi 15 Dec 18, 2022
Color-Book - A simple color book made with compose

Color-Book A simple color book made with compose

mhssn 3 Feb 16, 2022
Kotlin-Exposed-SQL - Example of using Exposed with Kotlin for the consumption of relational SQL Databases

Kotlin Exposed SQL Sencillo ejemplo sobre el uso y abuso de Exposed ORM de Jetbr

José Luis González Sánchez 3 Jun 14, 2022