How to create and run Jasper Report with JSON data passed to it via REST?


Jasper Reports newbie here...

In a nutshell, what I am looking to do is have a Jasper Report that uses json as a data source, that is passed to it at execution time, via the REST API.

In more detail... The json data would come from my ERP system and would be sent to the Jasper Server as part of the web request to run the report. The output in general would be PDF, but sometimes Excel, CSV, or HTML depending on the report and the needs of the user. What are the high-level steps to do this, and can you point me in the direction of the documentation that covers each step?

I have created a Jasper Report in Jaspersoft Studio, that uses a json file as its datasource via a DataAdapter. I have the Jasper Server installed and running as a Docker instance against a Mariadb cluster. Now I just need to connect the dots. The Jasper Reports server would not have direct access to the ERP system database, hence using Jasper as a web service and passing it the data I want to use in the report. Program language doesn't matter per se, but C# or Visual Basic examples would be ideal. I understand the basic concept of sending a POST request to run the report, but I don't see a way in the API that you can pass the report the data to use during execution.

Thanks in advance for any assistance anyone can provide!


trboyden's picture
Joined: Feb 6 2017 - 4:03pm
Last seen: 9 months 4 days ago

As an update, and so hopefully Googlers can find a decent example to get themselves going, here is some example VB.Net code that works:

Imports System.Net
Module ModuleMain
    Sub Main()
        ' WebClient Class Implementation '
        Dim wc As WebClient = New WebClient()
        ' Authorize the http request '
        Dim cc As CredentialCache = New CredentialCache()
        cc.Add(New Uri("http://<JasperServerHostname>:8080/"), "Basic", New NetworkCredential("admin", "admin"))
        wc.Credentials = cc
        ' Set the base address of the Reports service '
        wc.BaseAddress = "http://<JasperServerHostname>:8080/jasperserver/rest_v2/reports/"
        ' Create the inputControl parameter to send to JasperServer as a QueryString parameter '
        Dim data As Specialized.NameValueCollection = New Specialized.NameValueCollection()
        data.Add("jsonString", Uri.EscapeDataString("[{""CustNum"":""      2"",""CustSeq"":""0"",""Name"":""Coordinated Bicycles - North""}]"))
        wc.QueryString = data
        ' Setup the file to download the report to '
        Dim outputBasePath As String = "\\<ERPServerReportOutputDirectory>\"
        Dim fileName As String = "CustomerReport-" & DateTime.Now.ToString("yyyyMMdd_HHmmssff") & ".pdf"
        ' Submit the http request and get the output resource '
        wc.DownloadFile("Reports/CustomerReport.pdf", outputBasePath & fileName)
        ' Launch the PDF file using the default PDF viewer application '
        System.Diagnostics.Process.Start(outputBasePath & fileName)
    End Sub
End Module

Replace the values between "<Variable>" with your specific implementation configuration. As narcism mentioned, his answer, contains the information you need to setup the JasperReports jrxml file to use json as an inputControl /parameter to the report.

trboyden - 1 year 8 months ago

1 Answer:


First you should get somehow familiar with the REST API that is described here:

Based on that API, there is this Java client created by Jaspersoft: The Readme there covers a lot of topics.

If you're not into a Java-based solution you could use the API directly. My answer here: covers a similar topic to yours but starts off with how to pass XML data to sample report and then how to modify the report in order to pass JSON data.


narcism's picture
Joined: Nov 22 2010 - 12:39am
Last seen: 2 days 9 hours ago