Muhammad Ahmed
Muhammad Ahmed

Reputation: 53

How to pass json data to jasper report using rest

I am new to jasper. I have created a jasper report using JSON data source and pushed it to server. Is there a way to pass JSON data to the jasper report using rest call? I cannot find any example to follow.

Upvotes: 1

Views: 3652

Answers (1)

dada67
dada67

Reputation: 5103

If you have a report that has a json or jsonql query, what you can do is to provide a default value for the JSON_INPUT_STREAM builtin parameter based on the value of a another parameter that you create in the report. Something like this:

<parameter name="JsonData" class="java.lang.String">
</parameter>
<parameter name="JSON_INPUT_STREAM" class="java.io.InputStream">
    <defaultValueExpression><![CDATA[new ByteArrayInputStream($P{JsonData}.getBytes("UTF-8"))]]></defaultValueExpression>
</parameter>
<queryString language="json">
    <![CDATA[..json query..]]>
</queryString>

Than you'd need to create an input control for the JsonData parameter in the JasperReports Server report. If you have that you can pass a value for JsonData when running the report via REST:

  "parameters": {
    "reportParameter": [
      {
        "name": "JsonData",
        "value": [
          "{..json data..}"
        ]
      }
    ]
  }

Upvotes: 2

Related Questions