Textfield from JSON source has square brackets and quotes

Hi! I have a JSON datasource which is like this

 

{
     "tpExt": [
        {
            "organizationAddr": [
                {
                    "street": "8 High Street 08-01",
                    "postcode": "648123"
                }
            ]
        }
    ]
}

I have a field which is like this:

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

And my textfield is

<textField isBlankWhenNull="true">
    <reportElement x="110" y="114" width="430" height="17"/>
    <textElement lineSpacing="Single"/>
    <textFieldExpression><![CDATA[$F{street}]]></textFieldExpression>
</textField>

But I am getting the display with square brackets and quotes

["8 High Street 08-01"]

How to remove the square brackets and quotes? Thanks

alan.tham_1's picture
Joined: Sep 30 2019 - 12:29am
Last seen: 3 months 1 week ago

2 Answers:

I believe that in this case, the square brackets are indicating an array of values. So you are outputing an array (with just a single value in the array). If you treat it as an array in your TextField reference, you should be able to get individual elements. If you only expect one address ever, you can simply get the first element of the array and I think it will display as you desire.

mbielkiewicz's picture
Joined: Feb 23 2014 - 9:22pm
Last seen: 1 day 13 hours ago

Thanks! I changed my field to :

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

And it displayed as expected.

alan.tham_1's picture
Joined: Sep 30 2019 - 12:29am
Last seen: 3 months 1 week ago
Feedback
randomness