Jump to content
Changes to the Jaspersoft community edition download ×

How do I format JSON file as data source?


steve.shafer

Recommended Posts

I'm trying to use a JSON file as a data source for a report designed with Jaspersoft Studio 6.5.1.final.  I create the Data Adapter, pointing it to this file and selecting "Use the report JSON expression when filling the report".  The TEST button shows Success! but I don't get a list of fields anywhere to select from, and when I try to preview my report using this data adapter it complains the document is empty and shows 0 pages.  Can anyone please help?  I'm assuming the JSON file isn't formatted correctly, but I just don't know.

The JSON file:

{ "item" :
    [
        {
            "id": "12345",
            "name": "Donald Duck",
            "point": "x y",
            "total":  12345.0
        },
        {
            "id": "23456",
            "name" : "Yosemite Sam",
            "point": "u v",
            "total": 54321.0
        }
    ]
}

The report:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1  -->
<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="example" pageWidth="612" pageHeight="792" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="dbbccb9a-1990-400a-a676-0f51c05464a5">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Trial JSON Adapter"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 2">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 2_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 2_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 2_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 3">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 3_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 3_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 3_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 4">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 4_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 4_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 4_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 5">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 5_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 5_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 5_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <parameter name="HEADER" class="java.lang.String">
        <defaultValueExpression><![CDATA["BEGIN"]]></defaultValueExpression>
    </parameter>
    <parameter name="FOOTER" class="java.lang.String">
        <defaultValueExpression><![CDATA["END"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="name" class="java.lang.String"/>
    <field name="total" class="java.lang.Double"/>
    <field name="id" class="java.lang.String"/>
    <field name="point" class="java.lang.String"/>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="555" height="79" uuid="6c8bac56-3aea-4ef7-bf99-b9c0c6dadf63"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="30" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Example Label]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="60">
            <staticText>
                <reportElement x="0" y="30" width="153" height="20" uuid="6320b737-d8a5-4563-a16e-5cff508a2d08"/>
                <text><![CDATA[id]]></text>
            </staticText>
            <staticText>
                <reportElement x="153" y="30" width="302" height="20" uuid="d6949bb9-9960-4425-94e4-634f7a87bb5c"/>
                <text><![CDATA[name]]></text>
            </staticText>
            <staticText>
                <reportElement x="455" y="30" width="100" height="20" uuid="bb2bf7f4-79fc-458c-99b9-b5c6812770f7"/>
                <text><![CDATA[total]]></text>
            </staticText>
            <textField>
                <reportElement x="0" y="0" width="555" height="30" uuid="e003bd24-7355-40b5-9263-adff6a2ca43a"/>
                <textElement markup="html"/>
                <textFieldExpression><![CDATA[$P{HEADER}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="300" y="30" width="100" height="20" uuid="bc5602db-1986-4240-896f-e95dc34e59e3">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="0c96dd60-c92f-49a9-8ca2-430a1b7a137b"/>
                </reportElement>
                <text><![CDATA[point]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="122">
            <textField>
                <reportElement x="0" y="20" width="153" height="20" uuid="7108cc10-9366-45ab-b23d-d45db4db1c0c"/>
                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="153" y="20" width="137" height="20" uuid="1254f26c-0f15-4f10-9a1b-980e64fa3c44"/>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="455" y="20" width="100" height="20" uuid="02eff0fe-5c80-4e59-aee5-ecaaf8922a3d"/>
                <textFieldExpression><![CDATA[$F{total}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="300" y="20" width="130" height="20" uuid="38e9d773-9613-4062-9bb9-97c80bed4be2">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="0ba41536-a3e8-4211-ae00-097f3b7595f4"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{point}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="50">
            <textField>
                <reportElement x="0" y="0" width="555" height="50" uuid="6ed5397f-12b1-459e-9949-ed8429d729db"/>
                <textFieldExpression><![CDATA[$P{FOOTER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>
 

Thanks in advance!

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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...