Jump to content
Changes to the Jaspersoft community edition download ×

JSON ARRAY JSON Data source displaying null values


raval.chintan
Go to solution Solved by narcism,

Recommended Posts

Hi All, 

We are getting null in jasper soft studio with below inputs. We have Json Array in our json. We are using JsonDatasource. suprisingly, Json data source compute the number of elements in Json array however values are not getting printed. 

Is this bug with JsonDataSource?

we have below Json as data source. 

{

  "DataItem": {
        "AB-CDEF": {
         "GroupData": {
            "OGF": {
              "FRN": [
            "Chin-tan",    
            "14",
            "14",
            "14",
            "15"
          ]
        }
      }
    }
}
}

 

Below is our JRXML. 

 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.12.0.final using JasperReports Library version 6.12.1-ac0eebdb29e4c0985457bab279a6db744d661530  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Demo_Phone_list" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="cd0a2f09-0067-489b-8fe7-c8cbec7635c6">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="sample_list_phone_1"/>
    <subDataset name="Dataset1" uuid="5337e69f-16e4-447d-a9e7-fbe6d25a479f">
        <property name="com.jaspersoft.studio.data.defaultdataadapter"/>
        <queryString language="JSON">
            <![CDATA[]]>
        </queryString>
        <field name="FirmReferenceNumber" class="java.lang.String">
            <property name="net.sf.jasperreports.json.field.expression" value="[0]"/>
            <fieldDescription><![CDATA[FirmReferenceNumber]]></fieldDescription>
        </field>
    </subDataset>
    <queryString language="json">
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="100" splitType="Stretch">
            <componentElement>
                <reportElement x="346" y="30" width="320" height="60" uuid="46f04a61-454e-43e8-af82-f4b6490e2080"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                    <datasetRun subDataset="Dataset1" uuid="16a9a001-6c9b-4847-aa98-40b2c4c7296d">
                        <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("DataItem.AB-CDEF.GroupData.OGF.FRN")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="60" width="320">
                        <textField>
                            <reportElement x="100" y="19" width="188" height="30" uuid="4b05337f-4af5-4a13-a057-11324d2e4cff"/>
                            <box>
                                <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <textElement textAlignment="Center" verticalAlignment="Middle"/>
                            <textFieldExpression><![CDATA[$F{FirmReferenceNumber}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </band>
    </detail>
</jasperReport>
 

 

Regards,

Chintan

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

With JSON you need to change the field expression from "[0]" to ".", like so:

<field name="FirmReferenceNumber" class="java.lang.String">    <property name="net.sf.jasperreports.json.field.expression" value="."/>    <fieldDescription><![CDATA[FirmReferenceNumber]]></fieldDescription></field>[/code]

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...