JsonDataSource with JSON as Text (String)

1

 Hello, im new with jasper and ireport, but so far I could get a report exported to PDF using JsonDataSource coming from a file with JSON data in it.

 

Now what im tryying to do is get the same report filled with Json data coming as a String, is there any example or pointers to help me achieve this ?

 

In particular, I have a PHP application working, and using JavaBridge i get to connect jasper to it using JDBC or XML, I have all my querys working in the PHP application, what im trying to get is using the results of the PHP queries (that pop up as Json Strings) as input for the report, so i dont have to write my whole queries twice (one for reports and the same ones to display on the Web).

 

Thanks

millernegro's picture
Joined: Feb 17 2012 - 6:39am
Last seen: 2 years 1 month ago
This comment was blocked because Project Honeypot indicates it came from a suspicious IP address.
dasari16 - 1 year 5 months ago

12 Answers:

0

Hey!

I'm not able to add a JSON datasource. It accepts the JSON file as a source and the Test Connection icon says its successful,

but when I try to write a JSON query it tells me to activate a jdbc connection..

What'd you do?

 

 

P.S. I've added a couple of snapshots.Could you tell me what I'm doing wrong?



Post Edited by bookworm at 03/12/2012 06:33
bookworm's picture
Joined: Feb 5 2012 - 8:35pm
Last seen: 2 years 2 months ago

hey @bookworm, did you ever get this working? I'm trying to do the same myself. Thx

rsteier - 1 year 1 month ago
1

 whats an example of the JSOnData you will use ?

 

basically you add the fields and ignora that message, for example a json:

 

{records:[{id:int, description:string},{id:int, description:string},.........,{id:int, description:string}]}

in the "report query" you will add the property that contains the data (above example "record")

then manually go to the FIELDS option in the tree selector and add the fields ("id" and "description" in the above example, with the correct datatypes and description)

 

then just drag and drop those fields into the report and generate sample

millernegro's picture
Joined: Feb 17 2012 - 6:39am
Last seen: 2 years 1 month ago
0

Thanks for the reply millernegro.

I've attached the json sample that I'm using in the code section.

I've tried giving the name of the property that contains the data(in my case "glossary") as the query but no fields are displayed in the right, to drag and drop like in xml. 

Code:
<pre style="background-color: rgb(250, 240, 230); ">
{
    "glossary": {
        "title": "example glossary",
		"GlossDiv": {
            "title": "S",
			"GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
					"SortAs": "SGML",
					"GlossTerm": "Standard Generalized Markup Language",
					"Acronym": "SGML",
					"Abbrev": "ISO 8879:1986",
					"GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
						"GlossSeeAlso": ["GML", "XML"]
                    },
					"GlossSee": "markup"
                }
            }
        }
    }
}



Post Edited by bookworm at 03/13/2012 04:50



Post Edited by bookworm at 03/13/2012 04:54
bookworm's picture
Joined: Feb 5 2012 - 8:35pm
Last seen: 2 years 2 months ago
0
yes, it is not automatic, it doesn´t "read" the fields (like when you a sql query)

add the fields manually to the "FIELDS" list in the "TREE INSPECTOR" panel (right click - add)

the fields will appear at the bottom, on the right side it shows parameters send from "outside" the report. check in the samples folder, there is jsondatasource example with the ireport download.
millernegro's picture
Joined: Feb 17 2012 - 6:39am
Last seen: 2 years 1 month ago
0

 Have added the fields and renamed them to reflect the data that they are supposed to contain.

But when i try to add the query, again the fields disappear and the old "activate the jbc connection" message pops up.

Also, my parameter list isn't showing the JSON_INPUT_STREAM parameter. Do I have to add that too?

Have added a couple of snapshots..

 

P.S. I did check out the example in the samples folder but couldn't make any sense of it. Besides, it isn't even compiling.

Please help!

bookworm's picture
Joined: Feb 5 2012 - 8:35pm
Last seen: 2 years 2 months ago
0

 in the "report query" you have selected SQL as query language, use "json"

millernegro's picture
Joined: Feb 17 2012 - 6:39am
Last seen: 2 years 1 month ago
0

 here is an example using your json (see attachment) of the query, see the FIELDS part, and the report generated.

 

for some reason that i dont know, if the field has a NAME but has no description (or a description different than the name) it prints as null. so when create the field, set the name (path of properties in the json), the type and set the description with the same value of the name

millernegro's picture
Joined: Feb 17 2012 - 6:39am
Last seen: 2 years 1 month ago
This comment was blocked because Project Honeypot indicates it came from a suspicious IP address.
nitinsahu - 1 year 5 months ago
0

 It worked!

Thank you so much millernegro..:)

bookworm's picture
Joined: Feb 5 2012 - 8:35pm
Last seen: 2 years 2 months ago

Could you post your code? Specifically, what you put exactly in the NAME and DESCRIPTION properties of your field. Thanks much!

rsteier - 1 year 1 month ago
0

Hi,

I'm using iReport to create some templates. I have a JSON like this

 

{
    "getorder": {
        "err": "0",
        "errdesc": "",
        "orderdata": {
            "id": 26,
            "state": "finished",
            "orderitems": [
                {
                    "id": 16,
                    "codigohoja": "3640IV-8B"
                },
                {
                    "id": 16,
                    "codigohoja": "3640IV-8B"
                }
            ]
        }
    }
}



I have a main report that shows id and state fields from getorder.orderdata select fine.

I've created a subreport to show orderitems with select getorder.orderdata.orderitems and it work fine if I execute it alone, but no results when run as subreport.

I think should be a connection problem or something similar. Has anyone tried this?

 

Thanks

dverdu's picture
1
Joined: Apr 18 2012 - 4:30am
Last seen: 1 year 12 months ago
0
Code:
Did you try do deploy it on server? I can find a way to work on server with json datasource.</td></tr></tbody></table>
darko87's picture
Joined: May 31 2012 - 2:01am
Last seen: 1 year 4 days ago
0
Hi, I only seem to get this working with simple field names (eg. title) and not with a json path (eg. GlossDiv.title). It then just shows an empty result (not 'null') and no errors are thrown.
When I use glossary.GlossDiv as my report query I can show its titles...
I'm working with iReport version 4.7.
Any ideas?
clearfacts's picture
Joined: Aug 30 2012 - 12:35am
Last seen: 7 months 2 weeks ago
0
I am seeing exactly the same thing. I can use root "row", but when I try to either define my query as row.items with simple names or just use row and item.name I get a blank reading. The reports seems to traverse through the rows however.
I sort of lost in forum discussion found and not sure whether iReport differs from jasterreports. I tried the sample provided there (using complex names) but no luck.
axelgunn's picture
Joined: Aug 22 2012 - 2:18am
Last seen: 1 year 7 months ago
Feedback