How to Create a Jasper Report Using JSON Data in Table Format

Posted on by By Satya Gopi, in Jaspersoft | 0

Prerequisite: Jasper Studio, MYSQL, Jasper sever

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

I have come across one issue, our client has data in JSON format for one field and he is expecting to create a report like below format

Json Format :

{

"alert_events":

[

{"event":"FD Alert","date_created":"2018-07-29 17:47:18<br />Africa/Abidjan","info":"Location: 22.9465931 -25.4185405","extra":""}

,{"event":"Received","date_created":"2018-07-29 17:47:20<br />Africa/Abidjan","info":"","extra":""},

{"event":"Acknowledged","date_created":"2018-07-29 17:47:26<br />Africa/Abidjan","info":"","extra":""},

{"event":"Resolved","date_created":"2018-07-29 17:49:43<br />Africa/Abidjan","info":"without_dispatch","extra":""},

{"event":"Alert Note","date_created":"2018-07-29 17:49:38<br />Africa/Abidjan","info":"2018-07-29 13:47:26 ","extra":""}

]

}

Data in Table

jaspersoft report with Json

Expected Output

jaspersoft report json output

To achieve above output we need use Scriplet concept in Jasper nothing but one Java Program to convert JSON format to a list format then we can pass that list to report

In Java program, we need to use two classes one is Bean Class and other for Conversation.

Bean Class:

Bean Class

JSON Conversation:

JSON Converstion

We need to convert this program to jar and place that JAR at Jasper lib folder and also dependencies jar also

JSON LIB

Create a Scriptlet in Jasper and class we need to give package name along with class name

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Get your 30 Days Trail Version

script let

I have created a Main Report and One SubReport

Main Report I have placed device_user and device_id, Organization name in Group

Sub Report I am passing the main object which names as alert_events in the datasource expression

expression editor

In SubReport just I have placed the attributes names in detail band, here we no need to write any SQL in the main dataset

main report

If you need to check the output in Jasper Studion then we need main and dependency jars in Report Library

Come to main Report and preview the output is as follows

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Lets Register For Live Demo

json output

logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

If you have any queries please get us at support@helicaltech.com

Thank You

Satya Gopi

Helical IT Solutions Pvt Ltd

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments