tree: 2e0520bdf9916b71adc3907576a0d3d50c2b1f11 [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.md
json-generation/README.md

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.