JSON File String List Table
Posted on May 4, 2023 at 11:56pm
How can I print a list of strings (items) of a json file to a table in my report?
{
"propertyA": "sdsdfsdf",
"propertyB": "slkfgjdlfg",
"items": [
"ITEM1",
"ITEM2"
]
}
Joined: May 4 2023 - 7:25am
Last seen: 4 months 2 weeks ago
Posted on May 12, 2023 at 12:04pm
Yes it's possible to read json data and with a table or a chart it needs to be done through a sub dataset as you did.
The data can also be passed through a parameter value the same way and using the jsonql query language.
Joined: Mar 8 2011 - 2:06am
Last seen: 18 hours 6 min ago
Ok, I finally resolved it.
<subDataset name="myList">
<field name="itemName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="."/>
<fieldDescription><![CDATA[.]]></fieldDescription>
</field>
</subDataset>
.
.
<componentElement>
<reportElement positionType="Float" isPrintRepeatedValues="false" x="0" y="284" width="560" height="90" isRemoveLineWhenBlank="true" uuid="b8909323-e0d1-494b-a029-25352cbaf23e">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
<property name="com.jaspersoft.studio.components.autoresize.proportional" value="true"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="myList" uuid="d0f5042e-dda6-45ec-b033-2b6f4b9588b1">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("items")]]></dataSourceExpression>
</datasetRun>
<jr:column width="112" uuid="b5c22fe9-766e-468c-8ee3-b753f1a9a48b">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="112" height="30" uuid="bf82d72a-4f7d-4a0a-8d56-a6506de3f072"/>
<text><![CDATA[Name]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="112" height="30" uuid="69977826-b68c-49f9-b73a-1d2d4e9faf67"/>
<textFieldExpression><![CDATA[$F{itemName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.