YARG - JsonPath syntax for a deeply nested sub-band

Hi

Consider the following situation:

Multiple companies have multiple employees. We want to show a simple report:

Company A:
- employee 1 name, address, etc
- employee 2 name, address, etc
...
Company B:
...
Company C:
...

We must use xlsx to use nested bands. We’re also using pure java and json to construct the report.
This is the fragment of report construction:

ReportBand employeesBand = bandBuilder.name("Employees")
    .orientation(BandOrientation.HORIZONTAL)
    .query("Employees", "parameter=Employees $.Companies[@].Employees", "json")
    .build();

ReportBand companiesBand = bandBuilder.name("Companies")
    .orientation(BandOrientation.HORIZONTAL)
    .query("Companies", "parameter=Companies $.Companies", "json")
    .child(employeesBand)
    .build();

reportBuilder.band(companiesBand);

// ...

reportParams.put("Companies", companiesJson);

The json looks like this:

{
   "Companies":[
      {
         "Employees":[
            {
               "number":678,
               "percent":50.0,
               "employeeName":"John Doe"
            }
         ],
         "companyName":"A"
      },
      {
         "Employees":[
            {
               "number":123,
               "percent":65.0,
               "employeeName":"Richard Roe"
            },
                        {
               "number":456,
               "percent":45.0,
               "employeeName":"John Cleese"
            }
         ],
         "companyName":"B"
      },
      {
         "Employees":[

         ],
         "companyName":"C"
      }
   ]
}

The problem and question:
I can generate a report with companies showing correctly, but I cannot get the employees to show. What should be the JsonPath query for a nested child? Or maybe the problem is in the java code. I think the xlsx is prepared correctly, with correct named ranges.

I suppose the $.Companies[@].Employees is wrong. Is it possible at all with json? Something like $.parentBand.Employees?

I think I’ve found the answer by debugging the JsonDataLoader. It looks like it is not possible to have a deeply nested sub-band using the json loader - at least without a fix.

In the JsonDataLoader:loadData the addParentBandDataToParametersRecursively succesfuly adds a Companies.Employees containing all employees in the currently iterated company.

Next, the parameterValue is searched for in the currentParams. The problem is - if the parameterValue should be found in the currentParams, it should be named Companies.Employees - and a “dot” is not possible in the parameter name, because the parameterPattern regex is limited to [A-z0-9_]+.

So I’ve created my own JsonDataLoader with the only change being a dot in the parameterPattern regex: [A-z0-9_.]+. Now the parameter named Companies.Employees can succesfuly be found in the currentParams.

Finally, with the above change, and the band query looking like this: parameter=Companies.Employees $.*, the sub-band works correctly in the report.

1 Like

Is there any progress on this issue? Im trying all possible ways to have the same situtation as described by @hduran

Is this Issue resolved in 2.2.4 version

Hi HDuran,
I am facing a similar issue…loading the data in child bands… Can you share the code plzz

@hduran
Aleast tell me what does “name”, “query”, “parameter” mean in this:- ReportBand employeesBand = bandBuilder.name(“Employees”)
.orientation(BandOrientation.HORIZONTAL)
.query(“Employees”, “parameter=Employees $.Companies[@].Employees”, “json”)
.build();