Skip to content
Glythcing edited this page Sep 17, 2018 · 4 revisions
Can I Read JSON?

Yes. See the simple example.


Can I Read a Map?

Yes. The parse() entry point accepts a Map. The following code will print out {"name":"tap"}:

Map<String, Object> incoming = new HashMap<>();
incoming.put("name", "tap");
incoming.put("quantity", 10);
System.out.println(Tranquil.parse(incoming).read("name", "quantity=10"));

Can I Read XML?

No (or maybe: not yet). Tranquil has an experimental feature which will accept XML and attempts to apply projections and predicates to it but it is not ready for use yet. If you are interested, watch (or contribute) to this issue.


Can I Read Nested Attributes?

Yes. See the nested example.


Can I Transform My Output To A Custom Type?

Yes. See the bespoke output types example.


Can I Pretty Print The Output JSON?

Yes. Tranquil can be configured with an instance of the underlying Jackson or Gson library which pretty prints JSON output.

For example:

Jackson
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
Tranquil.using(new JacksonMappingProvider(objectMapper))
  .parse(json)
  .read(select, where)
Gson
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Tranquil.using(new GsonMappingProvider(gson))
  .parse(json)
  .read(select, where)

Can I Match The Input Without Reading It?

Yes. The exists() entry point just applies the given predicates. No projections are involved and the return type is a boolean.

See the matching example.


Can I Select Without A Where Clause?

Yes. Use the select() entry point. For example: Tranquil.parse(json).select("name") will return a JSON document containing only the name attribute from the incoming JSON.


Can I Apply a Predicate Without A Select Clause?

Yes. Use the where() entry point. For example: Tranquil.parse(json).where("name = 'tap'") will return the entire incoming JSON as long as it contains an attribute name with the value "tap".