Related
I would like through a sql query to extract data from a json field in mysql8
TABLE :
id | int
game_at | datetime
scores | json
Registrations in mysql :
id : 1,
game_at : 2022-11-04 15:53:00
scores :
[
{
"tr": "4",
"tt": "10",
"type": "alpha",
"week": 44,
"id": "67"
},
{
"tr": "7",
"tt": "10",
"type": "alpha",
"week": 44,
"id": "71"
},
{
"tr": "7",
"tt": "10",
"type": "beta",
"week": 44,
"id": "67"
},
{
"tr": "8",
"tt": "10",
"type": "beta",
"week": 44,
"id": "71"
}
]
id : 2,
game_at : 2022-11-05 16:53:00
scores :
[
{
"tr": "2",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
{
"tr": "6",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "71"
},
{
"tr": "3",
"tt": "10",
"type": "beta",
"week": 45,
"id": "67"
},
{
"tr": "7",
"tt": "10",
"type": "beta",
"week": 45,
"id": "71"
}
]
id : 3,
game_at : 2022-11-04 17:53:00
scores :
[
{
"tr": "10",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
{
"tr": "6",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "71"
},
{
"tr": "9",
"tt": "10",
"type": "beta",
"week": 45,
"id": "67"
},
{
"tr": "1",
"tt": "10",
"type": "beta",
"week": 45,
"id": "71"
}
]
I tried this to start :
$sql ='SELECT scores->"$.type"
FROM adresse
WHERE scores->"$.poliste" = "67"
';
but it returns null?
For example, I would like to retrieve all the values where:
id: 67
type: alpha
{
"tr": "4",
"tt": "10",
"type": "alpha",
"week": 44,
"id": "67"
},
{
"tr": "2",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
{
"tr": "10",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
to create a table
I read that there is JSON_TABLE or substring_index but I don't understand how it works. An example would allow me to move forward Thank you in advance
In my project in Angular 5, I want to display in HTML code parameter "default_price":100, but my code display all default_price.
component.ts
this.ws.getAllProduct().subscribe(
products => {
this.products = products.map((product) => {
return new Product(product);
});
}
);
component.html
<div class="row">
<div class="input-field col s12">
<label for="unit_price" *ngFor="let item of products">{{item.default_price}}</label>
<input formControlName="unit_price" id="unit_price" type="number" class="validate" placeholder="unit_price">
</div>
</div>
Json:
{
"StatusCode": 0, "StatusMessage": "OK", "StatusDescription":
[
{
"product_id": "1",
"product_name": "Product1",
"description": "Product1",
"default_price": 50,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:26:17.000Z",
"active": 1
},
{
"product_id": "2",
"product_name": "Product2",
"description": "Product2",
"default_price": 60,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:35:17.000Z",
"active": 1
},
{
"product_id": "3",
"product_name": "Product3",
"description": "Product3",
"default_price": 80,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:35:22.000Z",
"active": 1
},
{
"product_id": "4",
"product_name": "Product4",
"description": "Product4",
"default_price": 100,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:25:54.000Z",
"active": 1
},
{
"product_id": "5",
"product_name": "Product5",
"description": "Product5",
"default_price": 120,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:35:27.000Z",
"active": 1
}
]
}
I want to display in html code only "product_id":"4", "product_name":"Product4".
Can you suggest me some idea?
You don't need ngFor if you need to display particular object, you can use array.find() to find particular element in the array
from your json, products.StatusDescription is the array
I have a Jasper report with a JSON datasource.
My Data Source Expression is:
(net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource()
When I try to see the preview, I get this error:
net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: ((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource()
[...]
Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: ((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource()
[...]
Caused by: java.lang.ClassCastException: net.sf.jasperreports.engine.fill.SortedDataSource cannot be cast to net.sf.jasperreports.engine.data.JsonDataSource
This is my Json file:
[
{
"appointmentId": 150,
"startDate": 1503039600000,
"patientId": 405,
"patientIdentification": {
"id": 1,
"name": "40295204D"
},
"episodeId": 500349,
"chn": "500046",
"patientName": "Cristina Mayo Saez",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "ENDOCRINOLOGIA",
"benefitId": 28,
"benefitName": "CONSULTA",
"schedule": {
"id": 26,
"name": "Nutrición"
},
"professionalName": "b",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503037036812
}, {
"appointmentId": 151,
"startDate": 1503039600000,
"patientId": 416,
"patientIdentification": {
"id": 1,
"name": "18466341D"
},
"episodeId": 500350,
"chn": "500057",
"patientName": "Gloria Sena Arrayán",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "b",
"insurance": {
"id": 1396,
"name": "AGRUPACION MUTUAL ASEGURADORA (AMA)"
},
"collective": {
"id": 30,
"name": "Trafico"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503038643436
}, {
"appointmentId": 153,
"startDate": 1503061200000,
"patientId": 417,
"patientIdentification": {
"id": 1,
"name": "85471254B"
},
"episodeId": 500358,
"chn": "500058",
"patientName": "Aida Mascaró",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 3,
"name": "Accidente de trabajo"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503057809579
}, {
"appointmentId": 154,
"startDate": 1503298800000,
"patientId": 389,
"patientIdentification": {
"id": 1,
"name": "23234567J"
},
"episodeId": 500359,
"chn": "500030",
"patientName": "maria perez perez",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "ENDOCRINOLOGIA",
"benefitId": 28,
"benefitName": "CONSULTA",
"schedule": {
"id": 26,
"name": "Nutrición"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503297627789
}, {
"appointmentId": 142,
"startDate": 1503298800000,
"patientId": 412,
"episodeId": 500337,
"chn": "500053",
"patientName": "Mariano López Pastor",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "b",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 25,
"name": "Privados todos"
},
"typeId": 1,
"guarantorStatus": {
"id": 7,
"name": "No requerida"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1502877885393
}, {
"appointmentId": 148,
"startDate": 1503300600000,
"patientId": 415,
"episodeId": 500346,
"chn": "500056",
"patientName": "Pastora Meseguer Carrión",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 25,
"name": "Privados todos"
},
"typeId": 1,
"guarantorStatus": {
"id": 7,
"name": "No requerida"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1502885871664
}, {
"appointmentId": 152,
"startDate": 1503302400000,
"patientId": 416,
"patientIdentification": {
"id": 1,
"name": "18466341D"
},
"episodeId": 500351,
"chn": "500057",
"patientName": "Gloria Sena Arrayán",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 46,
"benefitName": "REVISION",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "a",
"insurance": {
"id": 1396,
"name": "AGRUPACION MUTUAL ASEGURADORA (AMA)"
},
"collective": {
"id": 30,
"name": "Trafico"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503038674027
}, {
"appointmentId": 156,
"startDate": 1503302400000,
"patientId": 389,
"patientIdentification": {
"id": 1,
"name": "23234567J"
},
"episodeId": 500361,
"chn": "500030",
"patientName": "maria perez perez",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "PEDIATRIA",
"benefitId": 3,
"benefitName": "CONSULTA",
"schedule": {
"id": 29,
"name": "Dra. De la Vega"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"observations": "obs",
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503300374408
}, {
"appointmentId": 158,
"startDate": 1503303300000,
"patientId": 408,
"patientIdentification": {
"id": 2,
"name": "123123"
},
"episodeId": 500363,
"chn": "500049",
"patientName": "ANA CARO MARTINEZ",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "PEDIATRIA",
"benefitId": 3,
"benefitName": "CONSULTA",
"schedule": {
"id": 29,
"name": "Dra. De la Vega"
},
"professionalName": "b",
"insurance": {
"id": 1749,
"name": "ADMIRAL INSURANCE"
},
"collective": {
"id": 13,
"name": "Trafico"
},
"typeId": 1,
"observations": "dewdfe",
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503301904789
}, {
"appointmentId": 159,
"startDate": 1503304200000,
"patientId": 48,
"patientIdentification": {
"id": 5,
"name": "1425871"
},
"episodeId": 500364,
"chn": "186",
"patientName": "cayetana jimenez brotons",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "PEDIATRIA",
"benefitId": 4,
"benefitName": "REVISION",
"schedule": {
"id": 29,
"name": "Dra. De la Vega"
},
"professionalName": "b",
"insurance": {
"id": 1390,
"name": "MAPFRE ESPAÑA, CIA. DE SEGUROS Y REASEGUROS S.A."
},
"collective": {
"id": 4,
"name": "MAPFRE SALUD"
},
"typeId": 1,
"observations": "dfd",
"guarantorStatus": {
"id": 7,
"name": "No requerida"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503301999486
}
]
It seems that I can't cast the SortedDataSource into a JsonDataSource. Can anyone help me with this? Thanks.
I have a clean Jasper report that calls a subreport with no filter.
In that subreport I show all the Json data (10 rows), and if I see the preview it works: Subreport preview.
The problem is when I call the subreport from the main (and clean) report. It only has in the detail the professionalName and the subreport. It should show the professionalName and all the subReport (all 10 rows each time), but it's not the case. It only shows the current row, and I'm sure it's because the main report is not giving all the datasource to the subreport, only that row. Here is the capture: Main report preview.
The Data Source Expression is:
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource()]]></dataSourceExpression>
and the Json file is this one:
[ {
"appointmentId": 153,
"startDate": 1503061200000,
"patientId": 417,
"patientIdentification": {
"id": 1,
"name": "85471254B"
},
"episodeId": 500358,
"chn": "500058",
"patientName": "Aida Mascaró",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 3,
"name": "Accidente de trabajo"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503057809579
},
{
"appointmentId": 150,
"startDate": 1503039600000,
"patientId": 405,
"patientIdentification": {
"id": 1,
"name": "40295204D"
},
"episodeId": 500349,
"chn": "500046",
"patientName": "Cristina Mayo Saez",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "ENDOCRINOLOGIA",
"benefitId": 28,
"benefitName": "CONSULTA",
"schedule": {
"id": 26,
"name": "Nutrición"
},
"professionalName": "b",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503037036812
}, {
"appointmentId": 151,
"startDate": 1503039600000,
"patientId": 416,
"patientIdentification": {
"id": 1,
"name": "18466341D"
},
"episodeId": 500350,
"chn": "500057",
"patientName": "Gloria Sena Arrayán",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "b",
"insurance": {
"id": 1396,
"name": "AGRUPACION MUTUAL ASEGURADORA (AMA)"
},
"collective": {
"id": 30,
"name": "Trafico"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503038643436
}, {
"appointmentId": 154,
"startDate": 1503298800000,
"patientId": 389,
"patientIdentification": {
"id": 1,
"name": "23234567J"
},
"episodeId": 500359,
"chn": "500030",
"patientName": "maria perez perez",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "ENDOCRINOLOGIA",
"benefitId": 28,
"benefitName": "CONSULTA",
"schedule": {
"id": 26,
"name": "Nutrición"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503297627789
}, {
"appointmentId": 148,
"startDate": 1503300600000,
"patientId": 415,
"episodeId": 500346,
"chn": "500056",
"patientName": "Pastora Meseguer Carrión",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 25,
"name": "Privados todos"
},
"typeId": 1,
"guarantorStatus": {
"id": 7,
"name": "No requerida"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1502885871664
}, {
"appointmentId": 152,
"startDate": 1503302400000,
"patientId": 416,
"patientIdentification": {
"id": 1,
"name": "18466341D"
},
"episodeId": 500351,
"chn": "500057",
"patientName": "Gloria Sena Arrayán",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 46,
"benefitName": "REVISION",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "a",
"insurance": {
"id": 1396,
"name": "AGRUPACION MUTUAL ASEGURADORA (AMA)"
},
"collective": {
"id": 30,
"name": "Trafico"
},
"typeId": 1,
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503038674027
},{
"appointmentId": 156,
"startDate": 1503302400000,
"patientId": 389,
"patientIdentification": {
"id": 1,
"name": "23234567J"
},
"episodeId": 500361,
"chn": "500030",
"patientName": "maria perez perez",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "PEDIATRIA",
"benefitId": 3,
"benefitName": "CONSULTA",
"schedule": {
"id": 29,
"name": "Dra. De la Vega"
},
"professionalName": "a",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 26,
"name": "Privados"
},
"typeId": 1,
"observations": "obs",
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503300374408
},{
"appointmentId": 142,
"startDate": 1503298800000,
"patientId": 412,
"episodeId": 500337,
"chn": "500053",
"patientName": "Mariano López Pastor",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "NEUROLOGIA",
"benefitId": 45,
"benefitName": "CONSULTA",
"schedule": {
"id": 30,
"name": "Neurologia"
},
"professionalName": "b",
"insurance": {
"id": 1387,
"name": "PRIVADOS"
},
"collective": {
"id": 25,
"name": "Privados todos"
},
"typeId": 1,
"guarantorStatus": {
"id": 7,
"name": "No requerida"
},
"reason": {},
"appoState": {
"id": 4,
"name": "Atendido"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1502877885393
}, {
"appointmentId": 158,
"startDate": 1503303300000,
"patientId": 408,
"patientIdentification": {
"id": 2,
"name": "123123"
},
"episodeId": 500363,
"chn": "500049",
"patientName": "ANA CARO MARTINEZ",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "PEDIATRIA",
"benefitId": 3,
"benefitName": "CONSULTA",
"schedule": {
"id": 29,
"name": "Dra. De la Vega"
},
"professionalName": "b",
"insurance": {
"id": 1749,
"name": "ADMIRAL INSURANCE"
},
"collective": {
"id": 13,
"name": "Trafico"
},
"typeId": 1,
"observations": "dewdfe",
"guarantorStatus": {
"id": 1,
"name": "Solicitada"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503301904789
}, {
"appointmentId": 159,
"startDate": 1503304200000,
"patientId": 48,
"patientIdentification": {
"id": 5,
"name": "1425871"
},
"episodeId": 500364,
"chn": "186",
"patientName": "cayetana jimenez brotons",
"centerName": "HOSPITAL CLINICA BENIDORM",
"serviceName": "PEDIATRIA",
"benefitId": 4,
"benefitName": "REVISION",
"schedule": {
"id": 29,
"name": "Dra. De la Vega"
},
"professionalName": "b",
"insurance": {
"id": 1390,
"name": "MAPFRE ESPAÑA, CIA. DE SEGUROS Y REASEGUROS S.A."
},
"collective": {
"id": 4,
"name": "MAPFRE SALUD"
},
"typeId": 1,
"observations": "dfd",
"guarantorStatus": {
"id": 7,
"name": "No requerida"
},
"reason": {
"id": 2,
"name": "Accidente causal"
},
"appoState": {
"id": 3,
"name": "Atendiendo"
},
"appoType": {
"id": 1,
"name": "Simple"
},
"professionalCreationName": "Marisol Fernández Lleras",
"creationDate": 1503301999486
}
]
What can I do to pass the whole DataSet for each row I show? Thank you
The subDataSource method uses the current node when creating a new JsonDataSource instance. A future version of JasperReports will address this issue, but until then, you need to:
Remove the Data Source Expression from your subreport. The subreport itself is going to use a JSON data adapter.
Export your JSON data adapter to file. See step #2 from here in case you haven't done it before in Jaspersoft Studio.
In your subreport, set the report's Default Data Adapter property to point to your saved adapter from previous step. See step #4 from here.
Recompile your subreport if you're note building the project automatically.
I have the following json file I am importing into my component:
import { beer, wine, spririts, alcopop } from '../../config/calculator.json';
How can I use the json in my render?
Depending upon what was chosen I would like to use the data for each element, if user clicks beer, then show data for beer. For example, how would I loop through 'sizes' in 'beer'? This is my code so far:
{[drinkType].sizes.map((option, i) =>
<div value={option.id} key={i}>
{option}
</div>
)}
I would like to display the size name, pint, bottle, can etc
I get the error: Cannot read property 'map' of undefined
//calculator.json
{
"beer": {
"name": "Beer or cider",
"sizes": {
"568": {
"name": "Pint",
"size": 0.568,
"id": "pint",
"max": 10,
"icon": "beer_pint"
},
"440": {
"name": "Can",
"size": 0.44,
"id": "can",
"max": 10,
"icon": "beer_can"
},
"330": {
"name": "Bottle",
"size": "0.33",
"id": "bottle",
"max": "10",
"icon": "beer_bottle_330"
},
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "smallBottle",
"max": 10,
"icon": "beer_bottle_275"
}
},
"strength": [4, 4.5, 5, 6, 7, 8, 9]
},
"wine": {
"name": "Wine or champagne",
"sizes": {
"125": {
"name": "Small glass",
"size": 0.125,
"id": "small",
"max": 10,
"icon": "wine_small_glass"
},
"175": {
"name": "Standard glass",
"size": 0.175,
"id": "std",
"max": 10,
"icon": "wine_standard_glass"
},
"250": {
"name": "Large glass",
"size": 0.25,
"id": "large",
"max": 10,
"icon": "wine_large_glass"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 10,
"icon": "wine_bottle"
}
},
"strength": [9, 10, 10.5, 11, 11.5, 12, 13, 14, 15, 16, 17]
},
"spirits": {
"name": "Spirits or shots",
"sizes": {
"25": {
"name": "Single",
"size": 0.025,
"id": "single",
"max": 10,
"icon": "spirit_single"
},
"35": {
"name": "Large single",
"size": 0.035,
"id": "lgSingle",
"max": 10,
"icon": "spirit_large_single"
},
"50": {
"name": "Double",
"size": 0.05,
"id": "double",
"max": 10,
"icon": "spirit_double"
},
"70": {
"name": "Large double",
"size": 0.07,
"id": "lgDouble",
"max": 10,
"icon": "spirit_large_double"
},
"700": {
"name": "Bottle",
"size": 0.7,
"id": "bottle700",
"max": 3,
"icon": "spirit_bottles"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 3,
"icon": "spirit_bottles"
}
},
"strength": [37, 40]
},
"alcopop": {
"name": "Alcopop",
"sizes": {
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "small",
"max": 10,
"icon": "alcopops_small_bottle"
},
"330": {
"name": "Standard bottle",
"size": 0.33,
"id": "std",
"max": 10,
"icon": "alcopops_standard_bottle"
},
"750": {
"name": "Large bottle",
"size": 0.75,
"id": "large",
"max": 10,
"icon": "alcopops_large_bottle"
}
},
"strength": [5, 5.5]
}
}
.map does not work on objects like that,
map() is only for Arrays
Instead you can store the keys in array and use them, like,
import jsonData from '../../config/calculator';
...
//in constructor or any function
let sizes;
sizes={};
for(let i of Object.keys(jsonData)){
if(!sizes[i][0])sizes[i] = [];
for(let j of Object.keys(i.sizes)){
sizes[i].push(jsonData[i].sizes[j])
}
}
this.setState({
sizesArray:sizes
})
Now you can use this.state.sizesArray.map to iterate over sizes, like,
{this.state.sizes[drinkType].map((option, i) =>
<div value={option.id} key={i}>
{option}
</div>
)}
First, import your json inside the component:
import jsonData from '../../config/calculator'; //specify the appropriate location of the json file
Then you can access the "data" in your component in various ways. One way could be:
constructor() {
this.state = {
data: []
}
}
componentDidMount(){
this.setState({data: jsonData});
}
And accordingly, you can use this data(this.state.data).