Generar informe a partir de json tomado de mysql

0

I have a table on my db that has fields with jsonobject and jsonarray, I need to convert those values into jasperreport

<subDataset name="Dataset" uuid="06d196fb-4ae2-4735-9798-84a7072c4ea6">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
    <parameter name="data" class="java.lang.String"/>
    <queryString>
        <![CDATA[SELECT data1,data2,data3,data4,data5,data6
        FROM ri_table WHERE  id = $P{data}]]>
    </queryString>
    <field name="data1" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="data1"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
    </field>
    <field name="data2" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="data2"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
    </field>
    <field name="data3" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="data3"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
    </field>
    <field name="data4" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="data4"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
    </field>
    <field name="data5" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="data5"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="ri_pj_fugados"/>
    </field>
</subDataset>
<parameter name="data" class="java.lang.String"/>
<queryString>
    <![CDATA[SELECT data1,data2,data3,data4,data5,data6
        FROM ri_table WHERE  id = $P{data}]]>
</queryString>

That way I extract the data from the database

<summary>
    <band height="50">
        <property name="com.jaspersoft.studio.layout"/>
        <componentElement>
            <reportElement x="0" y="0" width="572" height="50" forecolor="#595959" uuid="1326f896-5433-4071-b733-25f1c836a830">
                <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                <property name="com.jaspersoft.studio.table.style.table_header" value="Table 1_TH"/>
                <property name="com.jaspersoft.studio.table.style.column_header" value="Table 1_CH"/>
                <property name="com.jaspersoft.studio.table.style.detail" value="Table 1_TD"/>
                <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
            </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="Dataset" uuid="e3de465d-85b0-414f-9f7e-704f827b366a">
                    <datasetParameter name="data">
                        <datasetParameterExpression><![CDATA[$P{data}]]></datasetParameterExpression>
                    </datasetParameter>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                </datasetRun>
                <jr:column width="70" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="70" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="8" isBold="true"/>
                            </textElement>
                            <text><![CDATA[data1]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="Table 1_TD" height="30">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement mode="Transparent" x="0" y="0" width="70" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="6"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{data1}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="90" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="8" isBold="true"/>
                            </textElement>
                            <text><![CDATA[data2]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="Table 1_TD" height="30">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement mode="Transparent" x="0" y="0" width="90" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="6"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{data2}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="70" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="70" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="8" isBold="true"/>
                            </textElement>
                            <text><![CDATA[data3]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="Table 1_TD" height="30">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement mode="Transparent" x="0" y="0" width="70" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="6"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{data3}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="41" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="41" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="8" isBold="true"/>
                            </textElement>
                            <text><![CDATA[data4]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="Table 1_TD" height="30">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement mode="Transparent" x="0" y="0" width="41" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="6"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{data4}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="61" uuid="300d2e97-ff2d-438b-8528-d565f835ccc8">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:columnHeader style="Table 1_CH" height="20" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="61" height="20" forecolor="#FFFFFF" uuid="5c21d9d0-510d-4852-904e-21a49992c04e"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="8" isBold="true"/>
                            </textElement>
                            <text><![CDATA[data5]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="Table 1_TD" height="30">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement mode="Transparent" x="0" y="0" width="61" height="30" forecolor="#595959" backcolor="#FAF5F5" uuid="4b036592-a8fa-405c-ac85-12f7cda5dabd"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font size="6"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{data5}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</summary>


That way it creates a table with the generated fields, but in the json data it prints them in the json format And I need for certain cases to print data2.dato or data2.otherdato


And I don't know how to do it, the same goes for the json array, I need to iterate the jsons inside the array and print out certain data.


The data is not constant, it is variable and each jsonarray should generate a table with its data

Attachments: 
luis.andres.carman's picture
Joined: Jul 1 2020 - 3:21pm
Last seen: 1 week 2 days ago

0 Answers:

No answers yet
Feedback
randomness