Create a Two-dimensional Table Based on JSON Data
【Question】
I have the this data:
data = [{“car”:“clear”,“number”:[“12”,“13”,“14”,“21”]},{“car”:“noClear”,“number”:[“34”]}]
I want to show it in the report like this:
clear
12 13 14 21
noClear
34
【Answer】
You can create a standard 2D table by converting the sequences under number field into space-separated strings, and give the table to JasperReport for presentation. You can handle the report data source preparation in SPL (Structured Process Language) in simple code:
A |
|
1 |
=file(“d:\\data.json”).read() |
2 |
=json(A1) |
3 |
=A2.new(car,number.concat(" "):col) |
Final result:
A1: json Read in the Json data.
A2: Create a table sequence based on A1.
A3: Convert number field values into space-separated strings and generate a new table sequence based on the strings.
You can connect to esProc in JasperReport via JDBC and call the SPL script in the same way as calling a stored procedure. For detailed information, see How to Call an SPL Script in JasperReport.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL