JSON Data Structure and Templates

Stimulsoft Reports.JS discussion
Post Reply
Doghousedev
Posts: 8
Joined: Thu Oct 11, 2018 10:34 am

JSON Data Structure and Templates

Post by Doghousedev »

I am getting my report data from a REST Service which provides valid JSON. I cannot change how the JSON data is formatted on the server side.

I am having a difficult time building an invoice which draws its sections from 4 different tables. Each REST call returns the data, however, the return JSON is always structured with the same Node naming (see below).

Does each JSON resource and data source need to be uniquely named? When I create a report template it always fails to Preview unless the 1st Node "platform" is unique. I can render reports fine using one JSON file, but cannot get it to work with more than 1 JSON data source.

ITEM DESCRIPTIONS

Code: Select all

{"platform": {
  "message": {
    "code": "0",
    "description": "Success"
  },
  "record": [
    {"description": "PROX,SLIDE PLT,15X10"},
    {"description": "Media Presentation Audio Amplifier"},
    {"description": "OFR IN-WALL END FITTING"}[
    }
LABOR CODES

Code: Select all

{"platform": {
  "message": {
    "code": "0",
    "description": "Success"
  },
  "record": [
    {
      "created_id": "af55a8e3284b46889b74c2088b0a26e5",
      "date_created": "2018-12-06T17:40:39.000Z",
      "date_modified": "2018-12-06T17:51:03.000Z",
      "ext_labor_rate": "2045.04",
      "ext_price": "3146.215384615384",
      "id": "101892637",
      "labor_phase": "1128024210",
      "labor_phase_text": "400-PROJECT-MGT",
      "labor_rate": "85.21",
      "modified_id": "af55a8e3284b46889b74c2088b0a26e5",
      "object_id": "2525f59f406642359cb8e99931f52ceb",
      "owner_id": "2121522889",
      "price_modifier": "P35",
      "qty": "24.0",
      "quote_related_to": "1684645886",
      "sell_price": "131.09230769230768"
    }]
    }
Lech Kulikowski
Posts: 7287
Joined: Tue Mar 20, 2018 5:34 am

Re: JSON Data Structure and Templates

Post by Lech Kulikowski »

Hello,

Please send us your report with test data which reproduces the issue for analysis.

Thank you.
Doghousedev
Posts: 8
Joined: Thu Oct 11, 2018 10:34 am

Re: JSON Data Structure and Templates

Post by Doghousedev »

SOLVED:

The solution to the problem is to rename the 'root' node of each JSON file.

In my javascript function, I simply used a string replacement with regex. I created a unique 'node name' for each JSON file processed.

It worked very well.
Andrew
Posts: 4108
Joined: Fri Jun 09, 2006 3:58 am

Re: JSON Data Structure and Templates

Post by Andrew »

Hello,

Thank you very much for sharing the solution.

Have a nice day!
Post Reply