-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Tranquil is a Java library which provides a SQL-esque language for querying JSON and Map
s.
Tranquil wraps a JSON de/serialization library and adds some predicate and projection capabilities. The inputs for these capabilities are expressed in SQL since many developers are likely to be familiar with using SQL to express select
and where
clauses.
That's quite a mouthful so have a quick look at the simple example for clarification.
Tranquil is intended to meet the following needs:
- Assessing whether a given
Map
structure or JSON string matches some predicates. For example:- Applying an assertion in a test case
- Querying a stream of objects/JSON to return only those which match some predicates
- Transforming a given
Map
structure or JSON string into another form (or format). For example, transforming:- A
Map
into JSON with different structure and/or field names and/or additional fields - JSON into JSON with different structure and/or field names and/or additional fields
- A
Tranquil uses ANTLR listeners to understand predicates and projections which are expressed using a SQL grammar. This grammar has some minor extensions to help cope with nested structures.
The input you supply is converted to a Map
(unless, of course, it is given as a Map
) using a standard JSON de/serialization library (Gson and Jackson are supported and configurable).
The ANTLR listeners create dynamic Groovy classes which are applied to the internal Map
.
The output can be further transformed, using the configured JSON de/serialization library, for example:
- To a
Map
- To JSON
- To a bespoke type
- To a collection of bespoke type