diff --git a/README.rst b/README.rst index 2dc5443..a17beac 100644 --- a/README.rst +++ b/README.rst @@ -371,6 +371,35 @@ See how easy it is to generate a report with a source an JSON file: print('Result is the file below.') print(output + '.pdf') +**Note 3:** + +JasperReports can process JSON files using either the `original JSON DataSource +`__ +or the `newer JSONQL Data Source +`__. +Refer to the JSONQL DataSource documentation for the differences. The example above +uses the JSON DataSource. To use the enhanced capabilities of the JSONQL DataSource +instead use: + +- the ``jsonql.jrxml`` input file +- the ``jsonql`` driver setting +- the ``jsonql_query`` query setting + +by changing these three parts of the example: + +.. code-block:: python + + ... + input_file = os.path.dirname(os.path.abspath(__file__)) + \ + '/examples/jsonql.jrxml' + ... + db_connection={ + ... + 'driver': 'jsonql', + 'jsonql_query': json_query, + }, + + Subreport Example ~~~~~~~~~~~~~~~~~ diff --git a/examples/jsonql.jrxml b/examples/jsonql.jrxml new file mode 100644 index 0000000..023a1b0 --- /dev/null +++ b/examples/jsonql.jrxml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="72"> + <frame> + <reportElement mode="Opaque" x="-20" y="-20" width="595" height="92" backcolor="#006699" uuid="d6b7d5aa-5c6b-4106-9569-b0014b63e753"/> + <staticText> + <reportElement x="20" y="20" width="267" height="43" forecolor="#FFFFFF" uuid="2932e85f-a2d7-40d5-9dad-0b5ea669ad15"/> + <textElement> + <font size="34" isBold="true"/> + </textElement> + <text><![CDATA[JasperStarter]]></text> + </staticText> + <staticText> + <reportElement x="298" y="43" width="277" height="20" forecolor="#FFFFFF" uuid="04e1a0ed-0b0f-41d4-93e9-792d4fd37d28"/> + <textElement textAlignment="Right"> + <font size="14" isBold="false"/> + </textElement> + <text><![CDATA[Report with JSONQL Datasource]]></text> + </staticText> + </frame> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pyreportjasper/jasperpy.py b/pyreportjasper/jasperpy.py index 87094da..0573f58 100644 --- a/pyreportjasper/jasperpy.py +++ b/pyreportjasper/jasperpy.py @@ -137,6 +137,9 @@ def process(self, input_file, output_file=False, format_list=['pdf'], if 'json_query' in db_connection: command += ' --json-query ' + db_connection['json_query'] + if 'jsonql_query' in db_connection: + command += ' --jsonql-query ' + db_connection['jsonql_query'] + if resource != "": if (resource == "."): command += " -r "