Problem with JasperSoft and dataset JSONQL [closed] - json

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I'm not an expert on soft jasper, so I think my problem is something trivial that I'm missing. I'm trying to create a DataSet using a JSONQL query, but my dataset remains empty. I create a list with this JRDataSource expression:
((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("prestazioni_a_confronto.verifica(tipologia == 'M')")
What am I doing wrong?
{
"id": 22399,
"prestazioni": [
{
"quantita": 10.000,
"verifica": {
"codice": "5M88A",
"tipologia": "M",
"descrizione": "mag.30% fascia prodottiva a (forfettaria annue)"
},
"unita_misura": "Numero"
}
],
"data_sopralluogo": "07/10/2022",
"controllore_principale": {
"cognome": "sys",
"nominativo": "admin"
},
"prestazioni_a_confronto": [
{
"quantita": 10.000,
"verifica": {
"codice": "A560",
"tipologia": "M",
"descrizione": "BOVINI ADULTI (di eta' uguale o superiore a 8 mesi)"
},
"fuori_fascia": false,
"unita_misura": "Capi"
},
{
"quantita": 1.000,
"verifica": {
"codice": "A562",
"tipologia": "M",
"descrizione": "SOLIPEDI/EQUIDI"
},
"fuori_fascia": false,
"unita_misura": "Capi"
}
]
}
<subDataset name="Prestazioni_M_DataSet" uuid="7284671c-397a-4e70-8ba6-cae72e73fe51">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="RicevutaPrestazioni_DataAdapter.jrdax"/>
<queryString language="jsonql">
<![CDATA[prestazioni_a_confronto.verifica(tipologia == "M")]]>
</queryString>
<field name="codice" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="codice"/>
<fieldDescription><![CDATA[codice]]></fieldDescription>
</field>
</subDataset>

I suspect that you have a mix of json and jsonql languages in your report.
Please make sure that you have:
your main query language(the one after the <subDataset /> element) set to jsonql, something like:
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
your list's dataSourceExpression is based on JsonQLDataSource and uses double quotes instead of single quotes, like this:
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("prestazioni_a_confronto.verifica(tipologia == \"M\")")]]></dataSourceExpression>

Related

Most elegant way to search for a json value and replace it in mysql? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a table called Entity which stores a bunch of jsons.
Entity
ID | Json
The Json is basically a array of json objects.
The order of the json objects is different each time...
[
{
"class" : "com.parallelorigin.code.ecs.components.Identity",
"id" : 0,
"tag" : "player",
"typeID" : "3:1"
},
{
"class" : "com.parallelorigin.code.ecs.components.transform.Transform",
"position" : {
"x" : 51.845858,
"y" : 8.299743
},
"previousPos" : null
},
{
"class" : "com.parallelorigin.code.ecs.components.collision.RangeCollider",
"range" : 0.000100
},
{
"class" : "com.parallelorigin.code.ecs.components.transform.Movement",
"moveTo" : null,
"speed" : 0.001000
},
{
"baseDamage" : 2,
"class" : "com.parallelorigin.code.ecs.components.combat.PhysicalDamage",
"damage" : 0
},
{
"class" : "com.parallelorigin.code.ecs.components.graphical.Mesh",
"id" : 6
},
{
"class" : "com.parallelorigin.code.ecs.components.items.Inventory"
},
{
"class" : "com.parallelorigin.code.ecs.components.combat.Health",
"health" : 100,
"maxHealth" : 100
},
{
"attackSpeed" : 1,
"baseAttackSpeed" : 1,
"class" : "com.parallelorigin.code.ecs.components.combat.AttackSpeed"
},
{
"class" : "com.parallelorigin.code.ecs.components.animation.AnimationController",
"controllerName" : "standardAnimationController"
}
]
I want to replace some of the class paths, add new fields to the json object, modify existing ones or remove them.
For example, i want to replace com.parallelorigin.code.ecs.components.Identity with com.parallelorigin.code.ecs.components.Identity, add a new "name" field to the same json object, adjust the existing tag and remove the typeID completly.
What is the most elegant/easiest way of modifiying that Json array in MySQL ?
You can get the element of the json array given a value:
mysql> select substring_index(json_unquote(json_search(json, 'one', 'com.parallelorigin.code.ecs.components.Identity')), '.', 1) as element from entity;
+---------+
| element |
+---------+
| $[0] |
+---------+
That gives the location of the element you need to replace. Then you can use JSON_REPLACE() to change it, something like this:
UPDATE Entity SET json =
json_replace(json,
substring_index(json_unquote(json_search(json, 'one', 'com.parallelorigin.code.ecs.components.Identity')), '.', 1),
json_object(
'class', 'com.parallelorigin.code.ecs.components.Identity',
'id', 0,
'name', 'some name')
)
WHERE id = 1;
That is the method, but there's nothing elegant about it. That's typical of using JSON in MySQL. Using JSON in an SQL database usually makes data manipulation much harder.
Using JSON in MySQL, you are practically certain to experience the Inner-Platform effect.
The elegant solution would be to store the data in a normalized fashion.

Naming convention recommendation for using mysql in nodejs [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
please give me your guidance.
I'm using node with mysql database (without using orm).
i use snake_case naming convention for mysql.
my question is:
in node,
should i use snake_case or use camelCase ?
for e.g. at models/movie.js:
snake_case:
return db.execute(SELECT title, daily_rental_rate FROM movies);
the result sent to the client:
{
title: 'abc',
daily_rental_rate: 20
}
camel_case:
return db.execute(SELECT title, daily_rental_rate as dailyRentalRate FROM movies);
the result sent to the client:
{
title: 'abc',
dailyRentalRate: 20
}
thank you so much /\
There is no fixed convention for JSON casing, however most APIs tend to use camelCase for properties, include Google, see their style guide here.
You can also map object properties within JavaScript, you don't have to do this manually in your queries. This allows you to be relatively flexible with your casing, even changing to kebab-case or snake_case if you wish to later on. This example uses the lodash library to convert object case.
const _ = require("lodash");
function objectToCamelCase(obj) {
return _.mapKeys(obj, (v, k) => _.camelCase(k))
}
let rows = db.execute("SELECT title, daily_rental_rate FROM movies");
console.log("Result (snake_case): ", rows);
rows = rows.map(objectToCamelCase);
console.log("Result (camelCase):", rows);
The results might look like so:
Result (snake_case):
[
{
"title": "The Shawshank Redemption",
"daily_rental_rate": "€2.99"
},
{
"title": "Ferris Bueller's Day Off",
"daily_rental_rate": "€2.99"
}
]
Result (camelCase):
[
{
"title": "The Shawshank Redemption",
"dailyRentalRate": "€2.99"
},
{
"title": "Ferris Bueller's Day Off",
"dailyRentalRate": "€2.99"
}
]

Coldfusion JSON

Currently I'm getting this output (QueryBean):
But I want the "normal" JSON output, like this one:
[
{
"EventType": "active",
"InstanceId": "6728E65C-XXXX-XXXXX",
"CustomerId": "1000324234",
"Name": "bilderbuchverein Hermsen"
"Amount": 999999,
"StartDate": "August, 01 2019 00:00:00",
"ExpirationDate": null
},
{
"EventType": "active",
"InstanceId": "956FA492-XXXX-XXXXX",
"Name": "Phantasialand"
"CustomerId": "12345678999",
"Amount": 123456789,
"StartDate": "August, 14 2019 00:00:00",
"ExpirationDate": null
}
]
How can I manage to change the output format? My function has the parameter produces="application/json"
<cffunction name="listEvents" access="remote" returnType="any" produces="application/JSON" httpmethod="GET" restpath="/events">
<cfquery datasource="hostmanager" name="plannedInstances">
SELECT * FROM licenses
</cfquery>
<cfreturn plannedInstances>
</cffunction>
To get JSON output data as an array of structure, you can use Application-level defining. In Application.cfc by adding this.serialization.serializeQueryAs = "struct" you can get serialize JSON output data as an array of structure like below.
[
{
"CATEGORYID":20,
"CATEGORYNAME":"php",
"CATEGORYDESC":"php"
},
{
"CATEGORYID":21,
"CATEGORYNAME":"cf",
"CATEGORYDESC":"cf"
},
{
"CATEGORYID":22,
"CATEGORYNAME":".Net",
"CATEGORYDESC":".net"
}
]
I have used the same code with my test table. (please see the example code result screenshot)
Also, you can refer SerializeJSON 'Additional format for query serialization' I think you can't able to handle this issue with produces="application/json"
I hope It's useful for you!
There are two steps to achieve your goal.
Create and return an array of structures instead of a query ( Which fully based on CFML side )
Use the ParseJson method in jQuery to parse the response from CF.
Here is an example of returning an array of structures in JSON format. It creates a single array, and populates it with individual structures inside the query loop. Insert the query column names as the structure key, and finally append the structure into the root array. Finally, return that array from the function.
<cffunction name="sampleCall" access="remote" returntype="any" returnformat="JSON">
<cfquery name="read" datasource="myDataSource">
SELECT * FROM myTable limit 10
</cfquery>
<cfset myArray = [] >
<cfloop query="read">
<cfset myStr = {} >
<cfset structInsert(myStr, "logid", read.logid)>
<cfset structInsert(myStr, "log_datetime", read.log_datetime)>
<cfset structInsert(myStr, "log_Details", read.log_Details)>
<cfset arrayAppend(myArray,myStr)>
</cfloop>
<cfreturn myArray / >
</cffunction>
Note : The example uses sample columns from my query. You can use your own column names.
If you dump the result like the image below

how to parse a multidimensional array? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want the key and value of the following multidimensional array with key :followersperdate
{"version":"1.2","username":"LGUS","url":"http://t.co/ospRRVboge","avatar":"http://pbs.twimg.com/profile_images/378800000016800237/3787f02f0e0e10a0a19d9b508abd6ce2_normal.png","followers_current":38775,"date_updated":"2013-11-15","follow_days":"774","started_followers":544,"growth_since":38231,"average_growth":"49","tomorrow":"38824","next_month":"40245","followers_yesterday":37232,"rank":"14934","followersperdate":{"date2013-11-15":38775,"date2013-11-05":37232,"date2013-11-04":37126,"date2013-10-26":36203,"date2013-10-10":34384,"date2013-10-02":33353,"date2013-09-18":30870},"last_update":1384679796}
i cleared it for you, the object you want, has 7 sub objects, that can parse base on your language,
check this web page to learn more, choose your language, at the bottom of the site:
http://www.json.org/
if you are on a javaScript, check this http://www.w3schools.com/json/json_intro.asp
{
"version": "1.2",
"username": "LGUS",
"url": "http://t.co/ospRRVboge",
"avatar": "http://pbs.twimg.com/profile_images/378800000016800237/3787f02f0e0e10a0a19d9b508abd6ce2_normal.png",
"followers_current": 38775,
"date_updated": "2013-11-15",
"follow_days": "774",
"started_followers": 544,
"growth_since": 38231,
"average_growth": "49",
"tomorrow": "38824",
"next_month": "40245",
"followers_yesterday": 37232,
"rank": "14934",
"followersperdate": {
"date2013-11-15": 38775,
"date2013-11-05": 37232,
"date2013-11-04": 37126,
"date2013-10-26": 36203,
"date2013-10-10": 34384,
"date2013-10-02": 33353,
"date2013-09-18": 30870
},
"last_update": 1384679796
}

How can I represent list of data in JSON format? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am working on designing the JSON document of my data. Below is a single value (v) which contains site-id, price-score and confidence-score for now.
{
"v" : {
"site-id" : 0,
"price-score" : 0.5,
"confidence-score" : 0.2
}
}
Now, I want to add categories list into the above JSON document. As I am going to have multiple categories for a single value (v) so I came up with below JSON document-
{
"v" : {
"site-id" : 0,
"price-score" : 0.5,
"confidence-score" : 0.2,
"categories": [
{
"category-id": "123",
"price-score": "0.5",
"confidence-score": "0.2"
},
{
"category-id": "321",
"price-score": "0.2",
"confidence-score": "0.4"
}
]
}
}
Can anyone take a look and let me know if it looks good in the way I have added list of categories in the above JSON document? Or is there any better way of doing the same? As I don't want to start having problems when I am working on serializing and deserializing the above JSON document.
I recommend:
{
"v" : {
"site-id" : 0,
"price-score" : 0.5,
"confidence-score" : 0.2,
"categories": {
"123" : {
"price-score": "0.5",
"confidence-score": "0.2"
},
"321" : {
"price-score": "0.2",
"confidence-score": "0.4"
}
}
}
}
This way, you can easily use:
json.v.categories[id]
to get information about a specific category, instead of having to write:
var the_category;
for (var i = 0; i < json.v.categories.length; i++) {
if (json.v.categories[i]['category-id'] == id) {
the_category = json.v.categories[i];
break;
}
}
Another suggestion: use _ rather than - in the keys (or camelCase if you prefer), as hyphen prevents you from using . notation to access elements (notice that I had to write ['category-id'] above instead of .category-id.