jsonql query question

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?

ernestoo's picture
18940
Joined: Nov 29 2010 - 11:59am
Last seen: 5 years 11 months ago

That was it @narcism!! thank you so much

ernestoo - 5 years 11 months ago

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

narcism's picture
6460
Joined: Nov 22 2010 - 12:39am
Last seen: 2 days 38 min ago
Feedback