JSON for the report data source

Source: Internet
Author: User

JSON is widely used as a lightweight data format, and the need for reports to read JSON data sources for report development is also common, and some reports receive data from HTTP servers for report presentation. Here is an example of the process of using a JSON data source and an HTTP data source for each report.

generic JSON data source Report Description

student performance in the application of JSON files exist, it is necessary to summarize the student performance, and according to the total score, the results are presented in the report. The report style is as follows:


The JSON file contains classes, numbers, names, disciplines, scores, and other information in the following format:

[

{

"Class": "Class One",

"id": 1,

"Name": "Emily",

"Subject": "中文版",

"Score": 84

},

{

"Class": "Class One",

"id": 1,

"Name": "Emily",

"Subject": "Math",

"Score": 77

},

......

{

"Class": "Class One",

"id": 7,

"Name": "Nicholas",

"Subject": "PE",

"Score": 60

}

]

General reporting tools because the JSON file data cannot be read directly, it is often necessary to rely on custom datasets to be parsed by other high-level languages (such as Java) and passed to the report. The collection report can directly complete the reading and calculation of JSON data. The following steps are implemented:

writing a calculation script

Write a script (P1.DFX) using the Collector Editor, read the JSON format file, parse the content, and complete the calculation:

A1: After reading the contents of the JSON file in string format using read (), use the [email protected] () method to parse the contents of the JSON file into a sequential table;

A2: Group The student ID, summarize the total in the A3;

A4: Returns the result set for the report by A5, in descending order of total scores.

edit a report template

Create a new report, set the dataset, and use the "collector" DataSet type to invoke the edited script file (p1.dfx).


Where the DFX file path can be either an absolute path or a relative path, relative paths are configured in the relative option of the DFX home directory.

Edit the report expression to complete the report production directly using the result set returned by the collection script.

As seen through the above procedure, the use of the collector script can be very convenient to complete the reading of the JSON format file, and the external set of the script has a visual editing debugging environment, the edited script can also be reused (by other reports or programs called). However, if the script has been debugged and does not need to be reused, it would be cumbersome to maintain the consistency of the two files (both the set and report templates), which makes it easier to use the script dataset directly for the set report.

In the script dataset, you can step through the script to complete the calculation tasks, the syntax is consistent with the concentrator, and you can directly use the data sources and parameters that the report defines (this example is not covered). You can use the script dataset instead of the collector dataset (the Set Up script) section (the expression, and so on, which is exactly the same as using the Collector dataset, and no longer repeat):

JSON data source with hierarchy

In addition to the generic JSON format file, the aggregate report can be very well supported for JSON files with hierarchies. The order information and the order details under each order are listed according to the order and order schedule. The report style is as follows:

The JSON file includes order and order details in the following format:

[

{

"Order ID": "10248",

"Order Number": [

{

"Order ID": "10248",

"Product ID": "5",

"Unit Price": 12,

"Discount": 0,

"Quantity": 1

}

],

"Customer ID": "vinet",

"Date of issue": "2000-07-16",

"Arrival Date": "1996-08-01",

"Shipping fee": 32.38

},

{

"Order ID": "10324",

"Order Number": [

{

"Order ID": "10324",

"Product ID": "63",

"Unit Price": 35.1,

"Discount": 0.150000005960464,

"Quantity": 80

}

],

"Customer ID": "Savea",

"Date of issue": "1996-10-10",

"Arrival Date": "1996-11-05",

"Shipping fee": 214.27

},

{

"Order ID": "10325",

"Order Number": [

{

"Order ID": "10325",

"Product ID": "31",

"Unit Price": 10,

"Discount": 0,

"Quantity": 4

},

{

"Order ID": "10325",

"Product ID": "72",

"Unit Price": 27.8,

"Discount": 0,

"Quantity": 40

}

],

"Customer ID": "Koene",

"Date of issue": "1996-10-14",

"Arrival Date": "1996-10-23",

"Shipping fee": 64.86

},

......

{

"Order ID": "10399",

{

"Order ID": "10399",

"Product ID": "76",

"Unit Price": 14.4,

"Discount": 0,

"Quantity": 35

},

{

"Order ID": "10399",

"Product ID": "77",

"Unit Price": 10.4,

"Discount": 0,

"Quantity": 14

}

],

"Customer ID": "Vaffe",

"Date of issue": "1997-01-08",

"Arrival Date": "1997-01-14",

"Shipping fee": 27.36

}]

Write a script (P2.DFX) using the Collector Editor, read the JSON format file, parse the content, and complete the calculation:

Here you can see that the script reads the JSON format file with the hierarchy, directly resolves it to a hierarchical result set, and the set report can support this hierarchical data set.

The edited script file (P2.DFX) is called in the report dataset, and the resulting set of layers above is present in the report as a hierarchical dataset.

Edit the report expression to complete the report production directly using the hierarchical DataSet returned by the collection script.

It is worth noting that the use of hierarchical data sets, more information can be referred to the "run-dry set of dataset to understand the hierarchical dataset."

In addition, if we are reading a JSON file on a remote HTTP server (example), it provides a unified HTTP access interface to the outside world. Then the script only needs to make the following changes:

The remote HTTP file can be read directly using the Httpfile () function in A1, and the subsequent processing is exactly the same as the example one, no longer repeat.

It should be noted that the URL string in the Httpfile parameter points to any HTTP server, such as a servlet, to access the data returned by the Web service with parameters, such as: Httpfile ("http://192.168.1.101:6001/ Demo/servlet?action=4&name=report1&excelformat=2003 ", GBK) returns the result of Excel. Of course, the returned result can be plain-formatted text (such as CSV), or it can be a JSON string or an XML string, which can be processed by a collection report.

As you can see from these examples, the aggregate report directly supports read calculations for JSON-formatted files or remote HTTP files (whether editing a stand-alone set-up script or directly using a script dataset), facilitating the development of such reports and, on the other hand, explaining the importance of reporting tools supporting diverse data sources.



JSON for the report data source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.