Query JSON data using Golang (gojsonq)

gojsonq (A simple Go package to Query over JSON Data)

Most often developer needs to consume JSON data from other service and query over them. Querying JSON data is little time-consuming. For the last few days, I was working on a package (gojsonq) for Golang to query JSON data easily. The idea and inspiration comes from PHP-JSONQ by Nahid Bin Azhar.

Let's take a sample JSON data to start with:

sample-data.json

Now we are ready to query the data, let's see some examples

Query: select * from vendor.items where price > 1200 or id null

Using gojsonq we can do the query like:

example-1.go

Query: select name, price from vendor.items where price > 1200 or id null

Using gojsonq we can do the query like:

example-2.go

Query: select sum(price) from vendor.items where price > 1200 or id null

Using gojsonq we can do the query like:

example-3.go

Note you can use other aggregation function like Min/Max/Avg/Count`

Query: select price from vendor.items where price > 1200

Using gojsonq we can do the query like:

example-4.go

Note: You’ll get a plain array of price

Query: select * from vendor.items order by price

Using gojsonq we can do the query like:

example-5.go

Query: select description from .

Using gojsonq we can do the query like:

example-6.go

Let's find a deeply nested property and handle error properly:

example-7.go full example

There are some other useful methods available in the package. The package is still under heavy development! If you have any suggestion or bug report don’t forget to open an issue

If you are not using Go, you can also use the same implementation of the package using PHP, Javascript, Python and Kotlin. Links are listed below:

If you like the idea don’t forget to give a STAR :)

Github link for gojsonq

Software Engineer, Pathao Inc | Open Source Enthusiast | Love to write elegant code | Gopher by passion | https://thedevsaddam.github.io

Software Engineer, Pathao Inc | Open Source Enthusiast | Love to write elegant code | Gopher by passion | https://thedevsaddam.github.io