ernestoo Posted October 3, 2017 Share Posted October 3, 2017 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 More sharing options...
Solution narcism Posted October 4, 2017 Solution Share Posted October 4, 2017 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 More sharing options...
ernestoo Posted October 4, 2017 Author Share Posted October 4, 2017 That was it @narcism!! thank you so much Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now