Error JSONQL filter comparing between two nodes

Hi, first of all, I am not an expert using Jasper and JSONQL.

I am trying to use it and I get some problems when I write an expression that I need.

The input JSON i have is this:

  "customer": {
                "id"  : "Customer_20200305-1623-53ln-RQZX-95hasMTLJWa4",
                "href": "",
                "name"        : "Amit4598",
                "status"      : "Active",
                "statusReason": "Reason4",
                "engagedParty": {
                                  "type"   : "PartyRef",
                                  "refType": "Individual",
                                  "id"     : "Individual_01101404-0555-442e-8882-aaa2a02205f6",
                                  "href"   : null,
                                  "name"   : "givenName645130 familyName610747"
  "individuals": [
                    "id"  : "Individual_01101404-0555-442e-8882-aaa2a02205f6",
                    "href": "",
                    "givenName"         : "Rayko",
                    "middleName"        : "Stoyanov",
                    "familyName"        : "Pepelanov",
                    "formattedName"     : "Sr. Rayko Stoyanov Pepelanov",
                    "fullName"          : "givenName674627 middleName6042 familyName654554",
                    "preferredGivenName": "preferredGivenName",
                    "birthDate"         : "1980-08-18T12:16:47.447Z"
                    "id"  : "Individual_01101404-0555-442e-8882-aaa2a0220525",
                    "href": "",
                    "givenName"         : "paco",
                    "middleName"        : "Stoyanov",
                    "familyName"        : "Pepelanov",
                    "formattedName"     : "Sr. Rayko Stoyanov Pepelanov",
                    "fullName".         : "givenName674627 middleName6042 familyName654554",
                    "preferredGivenName": "preferredGivenName",
                    "birthDate".        : "1980-08-18T12:16:47.447Z"

What I need is to get the givenName json field from the individuals list whose id field has the same value as the id json field in

So, I have this expression:"Individual_01101404-0555-442e-8882-aaa2a02205f6")^.givenName

It works, but it has the static value of the id, and I want to get it from dinamically.

I have tried with some expressions but it doesn't work:^.givenName^^^.givenName^.^^.givenName$F{id})^.givenName    # being the id field the value of$P{id})^.givenName    # being the id parameter the value of$V{id})^.givenName    # being the id variable the value of

I don't know what to do. Please, could you help me to get the correct expression in order to get the id?

Thank you.

bmorata's picture
Joined: Apr 22 2020 - 8:35am
Last seen: 2 years 11 months ago

1 Answer:

If you are trying to filter inside a field expression, it is not possible. Filtering with values from the same JSON tree it is also not supported.

In your case you could filter in a subDataSource that you pass to a list like so:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version using JasperReports Library version 6.12.2-75c5e90a222ab406e416cbf590a5397028a52de3  -->
<jasperReport xmlns="" xmlns:xsi="" xsi:schemaLocation="" name="Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="119c58db-8ae4-4c92-8cd2-16ea09ccb158">
    <subDataset name="IndividualsDS" uuid="639a0f17-766f-42f5-bdfe-4157c94becfe">
        <field name="givenName" class="java.lang.String">
            <property name="net.sf.jasperreports.jsonql.field.expression" value="givenName"/>
    <queryString language="jsonql">
    <field name="customerId" class="java.lang.String">
        <property name="net.sf.jasperreports.jsonql.field.expression" value="id"/>
    <field name="customerName" class="java.lang.String">
        <property name="net.sf.jasperreports.jsonql.field.expression" value="name"/>
    <field name="customerEngagedPartyId" class="java.lang.String">
        <property name="net.sf.jasperreports.jsonql.field.expression" value=""/>
        <band splitType="Stretch"/>
        <band height="30" splitType="Stretch">
                <reportElement x="0" y="0" width="180" height="30" uuid="81411315-5690-4f34-a559-3f792e0aad89"/>
                <text><![CDATA[Customer Id]]></text>
                <reportElement x="180" y="0" width="185" height="30" uuid="1251081f-19ac-46cd-a22e-71159f586b76"/>
                <text><![CDATA[Customer Name]]></text>
                <reportElement x="365" y="0" width="185" height="30" uuid="b1e0c3a6-a04c-4bdd-99f3-f1a1e612a62c"/>
                <text><![CDATA[Individual Name]]></text>
        <band height="30" splitType="Stretch">
                <reportElement x="0" y="0" width="180" height="30" uuid="f6957d1f-1d6b-4855-8ced-af36ea456ff0"/>
                <reportElement x="180" y="0" width="185" height="30" uuid="2d38c046-a00f-40a0-8750-fd5c0d59018d"/>
                <reportElement x="365" y="0" width="185" height="30" uuid="9e0fdaa7-3cef-4e9c-97a7-715bf5ef499e"/>
                <jr:list xmlns:jr="" xsi:schemaLocation="" printOrder="Vertical">
                    <datasetRun subDataset="IndividualsDS" uuid="72b178d8-0026-4847-9760-ce82b0256e42">
                        <dataSourceExpression><![CDATA[(($P{REPORT_DATA_SOURCE}).subDataSource("^.individuals.*(id == \"" + $F{customerEngagedPartyId} +  "\")")]]></dataSourceExpression>
                    <jr:listContents height="30" width="185">
                            <reportElement x="0" y="0" width="185" height="30" uuid="ddd6c429-74ee-41ea-9914-f9ff4c44a8f3"/>

narcism's picture
Joined: Nov 22 2010 - 12:39am
Last seen: 9 hours 25 min ago