Jump to content
  • How to create a report that uses a remote JSON data source


    akonkin
    • Features: Data Sources Version: v8, v7 Product: JasperReports® Server

    In this article I would like to describe steps that would allow you to create a report that uses a remote JSON data source to provide a data for your report.

    Our test report will use a JSON data source:

    http://resources.finance.ua/ua/public/currency-cash.json (One can use any other JSON data API).

    2016-04-07_1559-1.png.94fe8b4819de69c84e8d586dff9cb5b5.png

    To create our report in JasperSoft Studio we need to:

    • create Data Adapter that can retrieve information from the remote JSON Data Source

      2016-04-07_1734-2.png.aac702af307ce958edcbbb6e97fd9d73.png

      click Test button to be assured that the data can be retrieved

      2016-04-07_1616-3.png.8914721d30d86825cee6054453f75b75.png

    • right click on the report name, select Dataset and Query and set our remote data source as the report’s data source (1), JSON as a query Language (2) , set a node from which the data should be extracted (3) and click Read fields (4)

      2016-04-07_1621-4.png.70f89b500786b2991497bd86f9ade95a.png

      a set of fields should be added to the fields area

    • add some of these fields to the Details band

      2016-04-07_1725-5(1).png.6d0a5ca90d8d6ba26b1087d09ef3874b.png

    • set default data source for this report

      2016-04-07_1726-6.png.1283f4cd8865589afaa61901862cad7b.png

    • run report and check the result of its execution

      2016-04-07_1735-7.png.506467b203a986c2f40dae25151364e1.png

      To export the report that has been created in the previous section we should:

    • export our Data Adapter to xml file

      2016-04-07_1737-8.png.6fd743cafbefc31a397b4c54363db04e.png

      upload this data adapter to JasperReports Server

      2016-04-07_1832-9.png.2e1e5ff6a69c7b33d295af5232682229.png

      2016-04-07_1833-10.png.6963c3d73513b0981cfbe451935ad3d2.png

      2016-04-07_1834-11.png.7c8f543b491f6a704f911c4c25697b7f.png

      2016-04-07_1834-12.png.2fd6fb53f88d71a85e0faa69022b6ad8.png

    • add to the jrxml report property that points to the data adapter

      <property name="net.sf.jasperreports.data.adapter" value="repo:/public/case_67889/Remote_JSON_Data_Adapter.xml"/>

      2016-04-07_1836-13.png.bb64fd78a00de236197b43843589a68b.png

      After this you can run your report in JasperReports Server:

      2016-04-07_1838-14.png.867e7552927e3357b6eea0b89e10130d.png

    2016-04-07_1559-1.png.7d179007ab8236199eec4e4da1b8342b.png

    2016-04-07_1734-2.png.41e4d24cc06949653276c225b8128717.png

    2016-04-07_1616-3.png.301f26f0235e185223a27196a926a8a3.png

    2016-04-07_1621-4.png.cee0a3e0fa6550ed4974a7e6a1dce078.png

    2016-04-07_1725-5(1).png.00ab8383568828e046fe5986060c6da5.png

    2016-04-07_1726-6.png.1c5c25630a37352614ac150a26c6b5b2.png

    2016-04-07_1735-7.png.608adb23a47e4c0c46aa79cdb40408b7.png

    2016-04-07_1832-9.png.d24a6d4f14c31455eb8fe1003b991325.png

    2016-04-07_1834-11.png.7a01627fe6aad0c47830e41f24e09909.png

    2016-04-07_1836-13.png.c5485cb4b298ad7164a127574aa7c4da.png

    2016-04-07_1838-14.png.c72c563b8850f07e0e78ccbe961d5f3e.png

    case_67889.zip

    remote_json_data_adapter.xml

    remote_json_data_source_test.jrxml


    User Feedback

    Recommended Comments

    Im using JSON datasource for work with jasper reports. In my host exist various database, and not is possible indicate where database is find info.

    If there is only one database, Datasource connects perfectly

    Link to comment
    Share on other sites

    In the "Dataset and Query" dialogue, when I click "Read" fields, I get the root nodes populated in my fields. (I expect to be able to select a non-root node, then see it's children populate the fields)
    Then when I do a "Data preview", I see all the JSON data as one long CSV string.
    I've tried a couple of private JSON files, but I'm having the same issue with public JSON sources, e.g.: https://services.odata.org/v4/TripPinServiceRW/People 
    Help please!

    Link to comment
    Share on other sites

    I am also stuck on parameterizing the request body when setting up the File/URL options.  I have a webservice which uses the JSON request body to determine what data will be returned.  I can send free text JSON and get a result...but I don't see how to parameterize values in that free text field when running the reports.

    Link to comment
    Share on other sites

    Hi,

    thanks for the explanations. But somehow I acnnot find where to get into the "Dataset and Query" dialogue.

    Is there a way to get into the resource wizard, when the datasource-adapter is already created?

    Link to comment
    Share on other sites

    Which versions of Jasper Studio and Jasper Server did you use for this tutorial? I'm using Jasper Studio 6.20.0 and Jasper Server 8.1.0 (both Community Edition), but I'm struggling with them.

    JSON datasources aren't working for me.

    I intend to follow your tutuorial using same versions as you did.

    Thanks in advance!

    Link to comment
    Share on other sites

    Hi, 

    Could you tell me which is the minimum version for this tutorial to work properly, please?

     

    Im using Jasper Studio 6.20 and Jasper Server 7.2 and im getting this error: 

    There was an error on the server. Try again or contact site administrators. (Error UID: e816c49c-a3ad-4bb6-8242-6ee5382baa0b)

    If I use paramaters for the URL the Input Control dialog is empty. 

     

    Thanks

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