Hi there, I have a json document/response that looks like this:
[ { "users.name": "Zulma Andrews", "users.age": 41 }, { "users.name": "Zona Christensen", "users.age": 54 } ]
There's no "name" for the main array so not sure what to put as the jsonql query expression - the fields are detected correctly but no data is returned...any ideas on what to try?
1 Answer:
Hi, Ernesto!
The main dataset query could be left empty in this case. I believe that what you have as field expression/description is not exactly what JSONQL expects. This should work:
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
<field name="users.name" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression">
<![CDATA[ ["users.name"] ]]>
</property>
<fieldDescription><![CDATA[User Name]]></fieldDescription>
</field>
<field name="users.age" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression">
<![CDATA[ ["users.age"] ]]>
</property>
<fieldDescription><![CDATA[User Age]]></fieldDescription>
</field>
In essence, to pick the users.name(or similar) key you need the ["users.name"] JSONQL expression. This happens because the users.name key is not a legal Javascript identifier an must be wrapped in quotes and surrounded by square brackets. It is similar to the Javascript way of accessing object keys.
More specific details could be found here: http://jasperreports.sourceforge.net/sample.reference/jsonqldatasource/i...
That was it @narcism!! thank you so much