Thursday, August 08, 2013

BIRT: Using JSON

This topic has come up quite a bit. Using JSON in BIRT Reports. This comes up for just about everything, from using as a Data Source to serializing large amounts of parameters for use in a report design. Seriously, lots of stuff.

Since the Rhino engine has not been updated to a version passed 1.7R4, there is no access to the nice Rhino JSON methods. So, we have have a few options. Since Rhino can use anything in the Java JVM, we can use any 3rd party JSON parser out there. My preference is Google GSON library. The caveat is that you must build the object structure beforehand in Java, and then use the GSON to parse a string into the object representation.

 There are other options as well, such as these: 
http://www.birt-exchange.org/devshare/_/designing-birt-reports/1053-scripted-data-source-using-json

 I ran across the old school method of using an eval() statement to do the same thing. While not as safe, this is a much simpler, quicker method, and will suffice in most cases. And example can be found here: http://www.birt-exchange.org/devshare/_/designing-birt-reports/birt-json-scripted-data-set-and-parameter-parsing-r1484

 Update: Kristopher Clark, whom is a very talented member of the BIRT community, posted something similar. In his example, he is using Apache Commons to stream in a JSON file and use as a scripted data source. This showcases BIRT's ability to leverage anything within the Java Classpath in a report execution.

No comments: