How to fill report using JSON datasource without getting null values?

From JasperReports – JSON Data Source Sample (version 6.4.3)

The built-in JSON query executer (see the JsonQueryExecuter class) is a tool that uses the query string to produce a JsonDataSource instance, based on specific built-in parameters (or equivalent report properties). This query executer is registered via JsonQueryExecuterFactory factory class.
In order to prepare the data source, the JSON query executer looks for the JSON_INPUT_STREAM parameter that contains the JSON source objects in the form of an java.io.InputStream. If no JSON_INPUT_STREAM parameter is provided, then the query executer looks for the alternate net.sf.jasperreports.json.source String parameter or report property that stores the path to the location of the JSON source file.
JsonQueryExecuter runs the query over the input source and stores the result in an in-memory JsonDataSource object.

So if you do not want to use:

<property name="net.sf.jasperreports.json.source" value="emp.json"/>

You need to pass the file as java.io.InputStream in the parameter JSON_INPUT_STREAM

Hence you are currently passing it as datasource you should try something like this

params.put(JsonQueryExecuterFactory.JSON_INPUT_STREAM, new FileInputStream(file));
JasperFillManager.fillReportToFile(jasperReport, params);

If you instead like to use the new JsonQLQueryExecuterFactory JSONQL Data Source

params.put(JsonQLQueryExecuterFactory.JSON_INPUT_STREAM, new FileInputStream(file));
JasperFillManager.fillReportToFile(jasperReport, params);

Leave a Comment