JSON Generation using JSR 374 APIs

This small sample demonstrates how to generate JSON using the JSR-374's JsonGenerator (thanks @enorman for mentioning that option) and how to test the results using JsonPath.

Generating JSON in this way looks like a good default method for Sling, as the only required dependency is our org.apache.sling.commons.johnzon module, which embeds those JSR-374 APIs as well as the Apache Johnzon core in a relatively small bundle (150kB as I write this).

The JsonGenerator is used in several of our modules already, searching for import javax.json.stream.JsonGenerator in the Sling codebase reports 26 results as I write this. This minimal example can help decide if it will also work for your use case.