Skip to content

Multiple objects in JSON data source #312

@Karyang

Description

@Karyang

Describe the bug
What's the correct way to access main and subs in Jasper Reports if there are multiple objects in JSON?

$extension = 'pdf' ;
$name = 'testeJasper';
$filename =  $name  . time();

$input = storage_path('app/public/relatorios/invoice.jasper');
$output = base_path('/public/reports/' . $filename);

$array = [
            [
              "category_id" => "1",
              "category_name" => "Module that will allow the pmmed to create a template first before cascading the PIs to offices from VP's OPCR"
            ],
            [
              "category_id" => "2",
              "category_name" => "Category 2"
            ],
            [
              "category_id" => "3",
              "category_name" => "Category 3"
            ]
        ];

$subReportSource = [
      ['program' => 'Higher', 'percentage' => '80%'],
      ['program' => 'Research', 'percentage' => '100%'],
    ];

$jsonArry = array('data' => ['main' => $array, 'subs' => $subReportSource ]);
$jsonTmpfilePath = storage_path('app/public'). '/relatorios/json/' . $name . '.json';
$jsonTmpfile = fopen($jsonTmpfilePath, 'w');
fwrite($jsonTmpfile, json_encode($jsonArry));
fclose($jsonTmpfile);
$datafile = $jsonTmpfilePath;

$options = [
        'format' => ['pdf'],
        'params' => [
          'msg' => "Display 101",
          'storage_path' => storage_path(),
        ],
        'locale' => 'en',
        'db_connection' => [
            'driver' => 'json',
            'data_file' => $datafile,
            'json_query' => 'data'
        ]
    ];

I tried to put this in my main.jrxml

<queryString language="json">
	<![CDATA[data.main]]>
</queryString>

and this one in my subReport.jrxml

<queryString language="json">
	<![CDATA[data.subs]]>
</queryString>

I just keep on getting this error
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions