rlothai Posted June 25, 2012 Share Posted June 25, 2012 Hello,I want to use the JsonDataSource in our bank project and have begun experimenting with it in iReport, with some success. Does anyone know if there is a third-party parsing engine being used or is this home grown? I could not glean the answer from a short look at the code. I need to locate a more or less complete reference for the query syntax, as I will be doing complex logic for some fields.I can so far grab values from within my own JSON string using syntax like: sections[0].fields[0].value in my fielddescriptions. I really need to be able to look for specific values of the keys for objects in an array, but cannot figure out what that syntax should look like. Later I will also need to show or hide fields based on boolean values stored with the fields (are functions available, and how?).I downloaded and got the JSON example working with the queryString syntax in the orders report: Northwind.Orders(CustomerID == $P{CustomerID} and was hoping to use something similar. So far I can't get the queryString to work with a similar lookup in my own json, and the == does not seem to work in fields either (not sure they are supposed to in fields, as not only can I not find documentation but I am also new to Jasper).While I can give you example JSON and have you solve the problem, what I would prefer is a link to some decent documentation I can digest and use myself.Thanks in advance and looking forward Link to comment Share on other sites More sharing options...
rlothai Posted June 26, 2012 Author Share Posted June 26, 2012 Hello, this is a bump with a more specific question. Assuming an object array with an embedded object array, like this:"sections": [{ "id": "section-Id-One", "property-One": true, "fields": [{ "id": "field-Id-One", "property-One": false, "property-Two": true, ... }, { "id": "field-Id-Two", "property-One": false, "property-Two": true, ... } .....I have succeeded in getting a query like this to work: sections(id == section-Id-One) But I cannot go deeper into the object graph, like:sections(id == sectionId).fields(id == field-Id-One)Seems nested arrays are a challenge. But I have a structure I cannot change and need to get at the properties. Is this supposed to work? Also, it would be great if someone just said, "oh, JSON queries in the datasource work like X or Y", or maybe "don't use this datasource because it's unfinished." Perhaps it's still too new, but I think it is an attractive option. Link to comment Share on other sites More sharing options...
mathias.gorf Posted November 19, 2012 Share Posted November 19, 2012 I am looking for a solution for this too! Link to comment Share on other sites More sharing options...
mathias.gorf Posted November 20, 2012 Share Posted November 20, 2012 The solution:sections(id == sectionId)[0].fields(id == field-Id-One)The explanation:the filtering expression sections(id == sectionId) does not necessarily return ONE object, in fact it returns an array of objects, which contains only one element in this case. Using this one object in an array has the same effect in jasper then if it would be a single object.For example, the array could contain all objects/sections which do not have this id: sections(id != sectionId)If one tries to access the array with the "." operator, it will fail anyhow.So if you know that the array only contains that ONE object, you can get it directly with "array[0]" Link to comment Share on other sites More sharing options...
narcism Posted June 17, 2014 Share Posted June 17, 2014 With a fix that originated from this issue: http://community.jaspersoft.com/jasperreports-library/issues/2500-0 (see post #2),it is possible to have a query string like you originally mentioned:sections(id == section-Id-One).fields(id == field-Id-One) Link to comment Share on other sites More sharing options...
lee.irvine Posted November 18, 2014 Share Posted November 18, 2014 If I change the JSON to something like: "sections": [{ "id": { "myid" : "section-Id-One" }, ... The Search doesnt seem to work anymore: sections(id.myid == section-Id-One).fields(id == field-Id-One) Does it support this kind of query in the JsonPath used in JasperReports as in XPath this is a standard lookup. Link to comment Share on other sites More sharing options...
guigui94 Posted September 27, 2017 Share Posted September 27, 2017 Is there a solution to get only 1 field : sections as a Json array with objets that are made of 3 attributes : "id" (string), "property-One" (boolean) and fields (json array of json objects) and then use expressions inside the report to show specific values Best regards, Guillaume 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