Jump to content
Changes to the Jaspersoft community edition download ×

How to assign a report field property value from JSON array element that has a particular value of one of its properties?


anatoly.weinstein
Go to solution Solved by Mehak Rajkumar,

Recommended Posts

I am new to Jasper and I am trying to do something like in the snippet below to get "value" of the "node" from the "proposal.proposalFees.nodes" array with "node.type" equal "KEY_2".
Obviously, the below snippet doesn't work. Question: how to do it properly?
The goal is that "$F{KeyTwoValue}" value displays "56000" in expressions (see sample data below).

Any input would be greatly appreciated.

    <queryString language="json">        <![CDATA[proposal]]>    </queryString>    <field name="KeyTwoValue" class="java.lang.String">        <property name="net.sf.jasperreports.json.field.expression">            <![CDATA[proposalFees.nodes[type == "KEY_2"].value]]>        </property>    </field>[/code]

Input source:

{  "proposal": {    "proposalFees": {      "nodes": [        {          "value": 20000,          "type": "KEY_1"        },        {          "value": 56000,          "type": "KEY_2"        }      ]    }  }}[/code]

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Actually, I have found an answer to my question here: jsonql datasource reference

This page has a good comparison for syntax and capability of JSON and JSONQL.

In question (with language="json") the proper field definition will looks like this:

    <field name="KeyTwoValue" class="java.lang.String">        <property name="net.sf.jasperreports.json.field.expression"                  value="proposalFees.nodes(type == KEY_2).value[0]"/>    </field>[/code]

 

Link to comment
Share on other sites

  • Solution

jsonql datasource reference

This page has a good comparison for syntax and capability of JSON and JSONQL.

In question (with language="json") the proper field definition will looks like this:

    <field name="KeyTwoValue" class="java.lang.String">        <property name="net.sf.jasperreports.json.field.expression"                  value="proposalFees.nodes(type == KEY_2).value[0]"/>    </field>[/code]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...