JSON of report data source

Source: Internet
Author: User

JSON of report data source

JSON is widely used as a lightweight data format. It is also common for reports to read json data sources for report development. In addition, some reports also receive data from HTTP servers for report presentation. The following example shows how to use the json data source and http data source in the next computing report.

General JSON data source report description

The student scores are in json format in the application. You Need To summarize the student scores and rank them according to the total scores. The results are displayed in reports. The report style is as follows:


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature/Signature/Co7o8L3A + CjxwPls8L3A + signature + ICAgfSw8L3A + signature + ICAgfSw8L3A + signature + signature + ICAgIHs8L3A + signature + yv2 + 3 aOszfnN + signature + 3byvzai5/cbky/u437y20 +/Signature + OxqLHt1PK/ ydLU1rG9083qs8lKU09Oyv2 + Platform + CjxwPiAgICAgICAgyrnTw7yvy + pg97hgvk1_97hg0ls9xbg + platform/Platform + Cgo8aW1nIHNyYz0 =" http://www.2cto.com/uploadfile/Collfiles/20150426/20150426091200522.jpg "Alt =" \ ">

A1: after reading the content of a json file in string format using read (), use the S. import @ j () method to parse the content of the json file into a sequential table;

A2: groups Student IDs and collects the total score in A3;

A4: in descending order of the total score, A5 is used as the report return result set.

Edit a Report Template

Create a report, set a dataset, and call the edited script file (p1.dfx) by using the dataset type of the Set calculator ).


The dfx file path can be either an absolute or relative path, and the relative path is the dfx home directory configured in the relative options.

Edit the report expression and directly use the result set returned by the Set Computing script to complete report creation.

Through the above process, we can see that using the set computing script can easily read and compute JSON format files, and the external set computing script has a visual editing and debugging environment, the edited script can also be reused (called by other reports or programs ). However, if the script has been debugged and does not need to be reused, It is troublesome to maintain consistency between the two files (the Set Computing script and Report Template, in this case, it is easier to directly use the script dataset of the Set Computing report.

In the script dataset, you can write scripts step by step to complete the computing task. The syntax is the same as that of the Set calculator. You can also directly use the data sources and parameters defined in the report (this example does not involve ). You can use the script dataset to replace the dataset (Set Computing script) section. (expressions and other parts are exactly the same as those used in the dataset. We will not repeat them here ):

JSON data sources with hierarchies

In addition to general json format files, computing reports can also be well supported for json files with hierarchies. The order information and order details of each order are listed based on the order and order list. The report style is as follows:

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

[

{

"Order ID": "10248 ",

"Order No ":[

{

"Order ID": "10248 ",

"Product ID": "5 ",

"Unit price": 12,

"Discount": 0,

"Quantity": 1

}

],

"Customer ID": "VINET ",

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

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

"Shipping fee": 32.38

},

{

"Order ID": "10324 ",

"Order No ":[

{

"Order ID": "10324 ",

"Product ID": "63 ",

"Unit prices": 35.1,

& Quot; Discount & quot;: 0.150000005960464,

"Quantity": 80

}

],

"Customer ID": "SAVEA ",

"Date of shipment ",

"Arrival date ",

"Shipping fee": 214.27

},

{

"Order ID": "10325 ",

"Order No ":[

{

"Order ID": "10325 ",

"Product ID": "31 ",

"Unit price": 10,

"Discount": 0,

"Quantity": 4

},

{

"Order ID": "10325 ",

"Product ID": "72 ",

"Unit prices": 27.8,

"Discount": 0,

"Quantity": 40

}

],

"Customer ID": "KOENE ",

"Date of shipment ",

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

"Shipping fee": 64.86

},

......

{

"Order ID": "10399 ",

{

"Order ID": "10399 ",

"Product ID": "76 ",

"Unit prices": 14.4,

"Discount": 0,

"Quantity": 35

},

{

"Order ID": "10399 ",

"Product ID": "77 ",

"Unit prices": 10.4,

"Discount": 0,

"Quantity": 14

}

],

"Customer ID": "VAFFE ",

"Date of shipment ",

"Arrival date ",

"Shipping fee": 27.36

}]

Use the set calculator editor to write scripts (p2.dfx), read json files, parse the content, and complete computation:

Here we can see that after the script reads a file in json format with a hierarchical structure, it is directly parsed into a result set with a hierarchical structure, and the Set Computing report can also support this type of dataset with hierarchical structure.

The edited script file (p2.dfx) is called in the report dataset. The preceding hierarchical result set exists in the report as a hierarchical dataset.

Edit the report expression and directly use the hierarchical dataset returned by the Set Computing script to create the report.

It is worth noting that the usage of hierarchical data sets. For more information, seeUnderstanding of hierarchical datasets of computing reports in rundry Sets].

In addition, if we read a json file (for example, one) on the remote HTTP server, it provides a unified HTTP access interface. The script only needs to make the following changes:

You can use the httpfile () function in A1 to directly read remote http files. The subsequent processing method is exactly the same as in Example 1.

It should be noted that the URL string in the httpfile parameter points to any HTTP server, such as a servlet, so that you can 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) the returned result is Excel. Of course, the returned results can be text in common format (such as csv), json or xml strings, and can be processed in both computing reports.

These examples show that the report supports reading and computing of json or remote http files (whether editing an independent set computing script or directly using a script dataset ), it facilitates the development of such reports, and also describes the importance of reporting tools to support diverse data sources.



Related Article

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.