Jump to content
We've recently updated our Privacy Statement, available here ×

Problem with JSON dataset


_freeman_
Go to solution Solved by narcism,

Recommended Posts

How can I fill data from json dataset that are not part of the array?

json.jpg.54f038838c6973e1a0ad048edd9e2aa6.jpg

Only array values get filled: 

pdfreport.jpg.49ec847f1098081eccfee93c859308f2.jpg

I searching for solution without table, because I have a long text that needs to be shown, and tables not working correctly with cells on one or more pages.

I've attached test jrxml and json file.

Thank you very much.

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

  • Solution

I'm posting only the relevant part, the query and the field mappings:

<queryString language="jsonql">    <![CDATA[list.*]]></queryString><field name="keyA" class="java.lang.String">    <property name="net.sf.jasperreports.jsonql.field.expression" value="keyA"/>    <fieldDescription><![CDATA[keyA]]></fieldDescription></field><field name="keyB" class="java.lang.String">    <property name="net.sf.jasperreports.jsonql.field.expression" value="keyB"/>    <fieldDescription><![CDATA[keyB]]></fieldDescription></field><field name="keyC" class="java.lang.String">    <property name="net.sf.jasperreports.jsonql.field.expression" value="keyC"/>    <fieldDescription><![CDATA[keyC]]></fieldDescription></field><field name="Title" class="java.lang.String">    <property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.title"/>    <fieldDescription><![CDATA[Title]]></fieldDescription></field><field name="Author" class="java.lang.String">    <property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.AUTHOR"/>    <fieldDescription><![CDATA[Author]]></fieldDescription></field><field name="Date" class="java.lang.String">    <property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.DATE"/>    <fieldDescription><![CDATA[Date]]></fieldDescription></field>[/code]

Some notes:

1. If you manually change the query language, from JSON to JSONQL, you also need to adjust the field-level properties to use the proper name: net.sf.jasperreports.jsonql.field.expression

2. JSON/JSONQL expressions are case sensitive

3. The JSONQL expression "^{2}.title" implies going up 2 levels from whatever your main query item points to, then select "title"

4. If your JSON data is part of a bigger JSON tree, then you need to adjust your main query expression from "list.*" to "..list.*" which will look for the "list" key anywhere in the JSON tree

Link to comment
Share on other sites

  • 2 months later...

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...