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

Json to populate report


freitas_tiago

Recommended Posts

Hello dear friends.

I'm using jasperSoft Studio 6.17.0 and I'm struggling with the following problem:

I have an input string parameter that , in fact, is a json structure. I have no data adapter, and I need to populate my report with the content of that parameter. I know how to do with a json file, but tried many things with json input as a string parameter.

{person: {name: "john", age: '22'}, car: {name: 'BMW', model: 'X3'}}

I haven't found any example in the net, so does anybody knows how to do that?

 

Thanks

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Thanks for your answer, but I made a full copy of your code but the report return only one null:

"<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.17.0.final using JasperReports Library version 6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Atestado" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="25dce969-32ae-4951-b8c6-6e55c8817291">
    <parameter name="jsonString" class="java.lang.String">
        <defaultValueExpression><![CDATA["{"a": [ {"b": { "val": "val1"}}, {"b": { "val": "val2" }}]}"]]></defaultValueExpression>
    </parameter>
    <parameter name="JSON_INPUT_STREAM" class="java.io.InputStream">
        <defaultValueExpression><![CDATA[new java.io.ByteArrayInputStream($P{jsonString}.getBytes("UTF8"))]]></defaultValueExpression>
    </parameter>
    <queryString language="JSON">
        <![CDATA[a.b]]>
    </queryString>
    <field name="value" class="java.lang.String">
        <fieldDescription><![CDATA[val]]></fieldDescription>
    </field>
    <columnHeader>
        <band height="31" splitType="Stretch">
            <staticText>
                <reportElement x="150" y="0" width="100" height="30" uuid="b33a123d-8987-4da4-b21b-1f9ccc50e92d"/>
                <text><![CDATA[value]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="150" y="0" width="100" height="30" uuid="14c51219-5ce2-47ce-abb9-71bc11a6f28c"/>
                <textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>"

The value I inserted in the prompt was:

{"a": [ {"b": { "val": "val1"}}, {"b": { "val": "val2" }}]}
and
{"a": [ {"b": { "val": "val1"}}, {"b": { "val": "val2" }}]}

The result was the same: null

Any idea?

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