This library for mapping JSON style query objects to SQL queries
You can use following Maven dependency:
<dependency>
<groupId>io.github.eaxdev</groupId>
<artifactId>jsonsql4j</artifactId>
<version>0.0.3</version>
</dependency>
implementation 'io.github.eaxdev:jsonsql4j:0.0.3'
Also, you can use GitHub Packages.
Given JSON:
{
"fields": [
{"column": "field1"},
{"column": "field2", "alias": "test"}
],
"from": [
{"table": "table1", "schema": "schema"}
],
"where": {
"or": [
{ "eq": {"fieldName": "field3", "value": "5"} },
{ "eq": {"fieldName": "field4", "value": "3"} }
]
}
}
use library:
Query selectQuery = new SelectQuery(jsonString);
String query = selectQuery.getQuery();
// query = SELECT field1, field2 AS test FROM schema.table1 WHERE (field3 = 5 OR field4 = 3)
You can find more examples here.
JsonSQL4J is open-source project, and distributed under the MIT license