Jump to content
We've recently updated our Privacy Statement, available here ×

JsonDataSource with JSON as Text (String)


millernegro

Recommended Posts

 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

Link to comment
Share on other sites

  • 4 weeks later...
  • Replies 17
  • Created
  • Last Reply

Top Posters In This Topic

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
Link to comment
Share on other sites

 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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 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!

Link to comment
Share on other sites

 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

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

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?

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...
  • 1 year later...

Did anyone get to work with JSON successfull ? I had tried with both - passing json as string, as a file, both is of no use, though the contents of the file, string are correct.

Though when i give the net.sf.jasperreports.json.source value to be a file location in ireport and eclipse plugin, the report is generated successfully. So the preview functionality works fine.

Seems like there is post which gives useful info, -

http://www.grantcurrey.com.au/blog/2013/01/26/using-jsondatasource-with-jasperreports/

Tried that too, nope not successfull, not sure how the author mentioned the properties value with -

  • net.sf.jasperreports.json.source
  • JSON_INPUT_STREAM

If anyone knows / can be helpful please do reply. Does anyone from jaspersoft monitors such threads ?

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