Jump to content
Changes to the Jaspersoft community edition download ×

jsonql query question


ernestoo
Go to solution Solved by narcism,

Recommended Posts

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    }][/code]

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?

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

  • Solution

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/index.html#jsonql

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