Json Extension

The JSON extension adds Jtwig the capability of converting Java objects to a String JSON representation. It includes a function json_encode to perform such operation.

{{ json_encode(object) }}

Under the wood, jtwig json extension will, using the configured mapper, convert the given object into a string.


            .add(new JsonExtension(JsonMapperProviderConfigurationBuilder

The configuration allows one to define multiple JsonMapperProvider, which supplies an instance of a mapper. The first use of the function json_encode will cause the mapper to be resolved and stored as singleton. Jtwig iterates over the list of JsonMapperProvider where the first one resolving will be used. By default, Jtwig defines two JsonMapperProvider, the Jackson2JsonMapperProvider and JacksonJsonMapperProvider which use, respectively, Jackson version 2 and 1.


Integrating Jtwig JSON Extension on your project is quite simple with the help of dependency managers. To check the most recent version, go to bintray.


repositories {
dependencies {
    compile 'org.jtwig:jtwig-json-extension:1.X'





Check the jtwig-examples project on github for examples using this render engine.