Jump to content
We've recently updated our Privacy Statement, available here ×
  • How to export my report to JSON format


    akonkin
    • Features: Exporters Product: JasperReports® Server

    Question:

    I am trying to retrieve a report that has a simple table in it using the following call

    http://<IP of my server>/jasperserver-pro/rest_v2/reports/Reports/restReportTest.json
    

    and getting the 204 No Content response.


    Answer:

    You should prepare your report to be able to export it to json format.

    For the detailed description of actions that should be done to achieve the desired result please refer to the JasperReports documentation:

    http://jasperreports.sourceforge.net/sample.reference/subreport/index.html#jsonmetadataexport
    

    From my part I would like to illustrate the document above with a sample of report that utilizes the properties that are required to export it to JSON.

    This report is a copy of AdHoc based report that is supplied with the software:

    (this AdHoc View uses Supermart Domain and Foodmart PostgreSQL database as its data source,  to be able to run this report please also install these resources with the product)

    /public/Samples/Reports/04._Product_Results_by_Store_Type_Report
    

    Please find the updated copy of this report in the folder:

    /public/export_to_json/04._Product_Results_by_Store_Type_Report
    

    To make this report “exportable” to JSON format it was opened in JasperSoft Studio:

    2016-02-02_1556-1.png.b15d5f51071090a3681f4505e2411598.png

    All reports fields were updated with the property:

    net.sf.jasperreports.export.json.path
    

    Below I quote an XML snippet that is related to the 1-st field (product name)

    2016-02-22_1010-2.png.fde3b828ac553401a28e5162c66add6d.png

    <property name="net.sf.jasperreports.export.json.path" value="product_name"/>
    

    The same property was added to the rest of the fields in this report. To export this report to JSON format

    rest_v2/reports
    

    REST v2 API get request should be executed from your browser.

    Below I quote a sample of URL that I used in my environment to test this solution:

    localhost:8620/jasperserver-pro/rest_v2/reports/public/export_to_json/04._Product_Results_by_Store_Type_Report.json
    

    Please pay your attention that .json extension was added to the report name to point to the application that export should be performed in JSON format.

    2016-02-22_1030-3.png.137df54d1f0db8cdd0d063ec1a242402.png

    Please find in the attachment to the article an exported copy of  the report and its jrxml body with the properties that are mentioned above.

    export_to_json.zip

    mainreportjrxml.txt


    User Feedback

    Recommended Comments

    There are no comments to display.



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