I have a JSON String:
{
06-2020={
ma01={
0={duur=Dag, aantalVoertuigen=2, tijd=14: 06, naamHuurder=K, prijs=70 },
1={duur=Dag, aantalVoertuigen=2, tijd=14: 08, naamHuurder=H, prijs=70 },
2={duur=Dag, aantalVoertuigen=2, tijd=14: 08, naamHuurder=H, prijs=70 },
3={duur=Dag, aantalVoertuigen=2, tijd=14: 08, naamHuurder=H, prijs=70 },
Aantal=4
}
},
05-2020={
hallo={auto=ja, naam=ja },
za30={hallo=ja, naam=ja }
}
}
I need to get the 06-2020 and the 05-2020 out of it.
I tried using JSONobject. But that only works with one layer.
Thanks in advance
Related
im using karate framework to test some site, but one call to the endpoints is like this: https://urlbase/index?id=60&filters[start_date]=Fri%20Nov%2018%202022%2010:14:59%20GMT-0300&filters[end_date]=Sat%20Nov%2019%202022%2023:59:59%20GMT-0300
And i have problems with the filters[...] i don't know how to do that :(
I have this query def:
* def query = {id: 60, filters[start_date]:'Fri%20Nov%2018%202022%2010:14:59%20GMT-0300', filters[end_date]:'Sat%20Nov%2019%202022%2023:59:59%20GMT-0300'}
But the request url shows: GET https://urlbase/index?id=60&filters=%7Bstart_date%3D%2C+end_date%3D%7D
`
with no brackets.
And i want my GET url looks like this: https://urlbase/index?id=60&filters[start_date]=Fri%20Nov%2018%202022%2010:14:59%20GMT-0300&filters[end_date]=Sat%20Nov%2019%202022%2023:59:59%20GMT-0300
I tried this and it seems to work fine:
* url 'https://httpbin.org/anything'
* param id = 60
* param filters[start_date] = 'Fri Nov 18 2022 10:14:59 GMT-0300'
* param filters[end_date] = 'Sat Nov 19 2022 23:59:59 GMT-0300'
* method get
You can look at the response and confirm the server handles the request correctly:
{
"args": {
"filters[end_date]": "Sat Nov 19 2022 23:59:59 GMT-0300",
"filters[start_date]": "Fri Nov 18 2022 10:14:59 GMT-0300",
"id": "60"
},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "gzip,deflate",
"Host": "httpbin.org",
"User-Agent": "Apache-HttpClient/4.5.13 (Java/17.0.4.1)",
"X-Amzn-Trace-Id": "Root=1-6377b983-6bfc4696374f7d08239de823"
},
"json": null,
"method": "GET",
"origin": "X.X.X.X",
"url": "https://httpbin.org/anything?filters[start_date]=Fri+Nov+18+2022+10%3A14%3A59+GMT-0300&filters[end_date]=Sat+Nov+19+2022+23%3A59%3A59+GMT-0300&id=60"
}
I reconnect with you. Since the last few times you have helped me and I have been with this problem for some time now and to solve it, my job depends because I am in practice and I have to solve it.
Mi JSON:
[
{
"fecha": "03/07/2018 08:16:58",
"velocidad_up": "30",
"velocidad_dw": "30",
"ppoe_usuario": "48575443596ACB9B",
"ppoe_password": "48575443596ACB9B",
"c": "0"
},
{
"fecha": "03/07/2018 08:23:13",
"velocidad_up": "30",
"velocidad_dw": "30",
"ppoe_usuario": "4857544321F99C9B",
"ppoe_password": "4857544321F99C9B",
"c": "0"
},
{
"fecha": "04/07/2018 18:58:02",
"velocidad_up": "5",
"velocidad_dw": "20",
"ppoe_usuario": "48575443DC26FB9B",
"ppoe_password": "48575443DC26FB9B",
"c": "0"
},
{
"fecha": "05/07/2018 08:33:00",
"velocidad_up": "10",
"velocidad_dw": "20",
"ppoe_usuario": "48575443DC23E79B",
"ppoe_password": "48575443DC23E79B",
"c": "0"
},
{
"fecha": "06/07/2018 18:50:29",
"velocidad_up": "5",
"velocidad_dw": "20",
"ppoe_usuario": "48575443A351D79B",
"ppoe_password": "48575443A351D79B",
"c": "0"
},
{
"fecha": "06/07/2018 18:53:13",
"velocidad_up": "5",
"velocidad_dw": "25",
"ppoe_usuario": "48575443DC26A59B",
"ppoe_password": "48575443DC26A59B",
"c": "0"
}
]
The fact is that when trying to generate a report in JASPER REPORT with dynamic columns from a JSON file, when arriving at the line where Jasper print is generated, the following error appears:
Exception in thread "main" net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: fecha.
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:193)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:158)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:104)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1489)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1390)
This error occurs on the line:
jasperPrint = JasperFillManager.fillReport(jasperReport, parametros, dataSource);
But in reality it is seen that NETBEANS gives a warning on the lines:
public static JRDataSource getDatasource(List<AbstractColumn> columns) throws FileNotFoundException {
Gson gson = new Gson();
JsonElement json = gson.fromJson(new FileReader("C:/tools/2datos-prue.json"), JsonElement.class);
datosJson = gson.fromJson(json, new TypeToken<List<JsonElement>>(){}.getType());
List data = new ArrayList();
data.addAll(datosJson);
List data3 = new ArrayList();
data3 = SortUtils.sortCollection(data, columns);
return new JRBeanCollectionDataSource(data3, false);
Specifically on the line:
data3 = SortUtils.sortCollection(data, columns);
giving the following errors:
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'fecha'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'velocidad_up'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'velocidad_dw'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'ppoe_usuario'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'ppoe_password'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'c'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'fecha'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare
ADVERTENCIA: java.lang.NoSuchMethodException: Unknown property 'velocidad_up'
ago 20, 2019 10:15:55 AM ar.com.fdvs.dj.util.MultiPropertyComparator compare ....
The error is repeated for each of the columns where the data is.
I am very overwhelmed by this problem ... I would like to help me .....
Thanks anyway to everyone, I hope your ideas hopefully find the solution...
The solution already works is that I read my JSON, like JRBeanCollectionDataSource and I must read it as DataSource pass it to jasper .....
How can I use Solrj to query Solr using the following api:
http://localhost:8983/solr/admin/zookeeper?detail=true&path=%2Fconfigs%2Fmy-search%2Fdataimport.properties
the above api gives the content of the dataimport.properties file.
{
"znode": {
"path": "/configs/my-search/dataimport.properties",
"prop": {
"version": 186,
"aversion": 0,
"children_count": 0,
"ctime": "Sun Oct 16 10:24:04 UTC 2016 (1476613444895)",
"cversion": 0,
"czxid": 479,
"ephemeralOwner": 0,
"mtime": "Fri Mar 24 09:48:50 UTC 2017 (1490348930211)",
"mzxid": 31451,
"pzxid": 479,
"dataLength": 111
},
"data": "#Fri Mar 24 09:48:50 UTC 2017\nname.last_index_time=2017-03-24 09\\:48\\:49\nlast_index_time=2017-03-24 09\\:48\\:49\n"
},
"tree": [
{
"data": {
"title": "dataimport.properties",
"attr": {
"href": "admin/zookeeper?detail=true&path=%2Fconfigs%2Fmy-search%2Fdataimport.properties"
}
}
}
]
}
btw, my Solr is configured in cloud mode.
Given that your Solr is running in Cloud mode the file /configs/my-search/dataimport.properties is into Zookeeper.
SolrJ does not have native API to easily read from Zookeeper.
To read into the Zookeeper I suggest to use use Apache Curator Framework
String dataPath = "/configs/my-search/dataimport.properties";
String connectionString = "zookeeper-ensemble:2181";
CuratorFramework client = CuratorFrameworkFactory.newClient(connectionString, new ExponentialBackoffRetry(1000, 3));
client.start();
byte[] barray = client.getData().forPath(dataPath);
if (barray != null) {
String data = new String(barray);
System.out.println(data);
}
I need some help on using elemMatch in spring data to query data in mongodb and retrieve results from mongodb.
I want to retrieve results for a particular testRun say testRun=1
I have the following data in mongodb:
[ {
"testMethod": "initialization",
"testCase": "com.harish.test.TestNGRest.OrganisationGetTest",
"build": 1,
"ranNumberofTimes": 2,
"failed": 0,
"success": 2,
"testRuns": [
{
"testMethod": "initialization",
"testCase": "com.harish.test.TestNGRest.OrganisationGetTest",
"branchName": "branch_1",
"testRun": 1,
"success": 1,
"fail": 0,
"timetorun": 0,
"cases": [
{
"caseId": 1,
"status": "success",
"failreason": null,
"startDate": "Fri May 27 14:41:22 EDT 2016",
"endDate": "Fri May 27 14:41:22 EDT 2016"
}
],
"startDate": "Fri May 27 14:41:22 EDT 2016",
"endDate": "Fri May 27 14:41:22 EDT 2016"
},
{
"testMethod": "initialization",
"testCase": "com.harish.test.TestNGRest.OrganisationGetTest",
"branchName": "branch_1",
"testRun": 2,
"success": 1,
"fail": 0,
"timetorun": 1,
"cases": [
{
"caseId": 1,
"status": "success",
"failreason": null,
"startDate": "Fri May 27 14:41:49 EDT 2016",
"endDate": "Fri May 27 14:41:49 EDT 2016"
}
],
"startDate": "Fri May 27 14:41:49 EDT 2016",
"endDate": "Fri May 27 14:41:49 EDT 2016"
}
]
In mongo console i used the following command and got the results:
db.test.find({"testRuns.testRun":1},{"testRuns":{"$elemMatch":{"testRun":1}}}).pretty()
I got the results for my requirement in mongo console.
The real question comes here, I used spring data in to retrieve the results in my java code.
return mongoTemplate.find(BasicQuery.query(Criteria.where("testRuns.testRun").is(testRun).andOperator(Criteria.where("testRuns").elemMatch(Criteria.where("testRun").is(testRun)))),Test.class, COLLECTION_NAME);
However, i'm not able to retrieve the results for a particular test run. Can someone please help me resolve this issue.
Thank you.
You don't need $elemMatch if you would like to get "testRuns.testRun" = 1. There is no second condition. Please refer the below statement in the mongo reference document link.
"Since the $elemMatch only specifies a single condition, the $elemMatch expression is not necessary, and instead you can use the following query:"
db.survey.find(
{ "results.product": "xyz" }
)
https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
I have tested with the below code with the data given in the post. It works fine.
Please make sure that the testRun variable is defined as Integer in Java code. If it is of other data type, the query wouldn't return result.
query.addCriteria(Criteria.where("testRuns.testRun").is(testRun));
mongoOperations.find(query, Stack.class);
I want to store the following JSON Array into MySql Database
My Requirement is to Synchronize the below data with MySql DB from an android Application.
[
{
"DATE":"Oct 15, 2015 7:09:23 AM",
"LNG":"75.124",
"LAT":"15.3647066",
"IMEI":"2",
"LOC":"Prabhat Colony"
},
{
"DATE":"Oct 15, 2015 7:09:41 AM",
"LNG":"75.0078",
"LAT":"15.4589233",
"IMEI":"2",
"LOC":"Hosayellapur"
},
{
"DATE":"Oct 15, 2015 7:15:56 AM",
"LNG":"74.4977",
"LAT":"15.849695",
"IMEI":"2",
"LOC":"Camp"
},
{
"DATE":"Oct 15, 2015 7:50:19 AM",
"LNG":"77.209",
"LAT":"28.6139383",
"IMEI":"2",
"LOC":"Rajpath Area"
},
{
"DATE":"Oct 15, 2015 7:50:41 AM",
"LNG":"77.391",
"LAT":"28.535515",
"IMEI":"2",
"LOC":"Sector - 106"
},
{
"DATE":"Oct 15, 2015 8:07:25 AM",
"LNG":"77.391",
"LAT":"28.535515",
"IMEI":"2",
"LOC":"Sector - 106"
},
{
"DATE":"Oct 15, 2015 8:20:26 AM",
"LNG":"77.391",
"LAT":"28.535515",
"IMEI":"2",
"LOC":"Sector - 106"
}
]
Can anyone please guide me on which is the best way to store JSON values to mysql Database?
You can create an object containing your attributes, and then deserialize your json to get an array of your object.
Then, you can then use JPA or another method to store your object in the database.
Unmarshal the steam into Predefined DTO classes. You can use GSon. Gson is an open source Java library to serialize and deserialize Java objects to (and from) JSON.
Gson gson = new Gson();
ClassName className = gson.fromJson(data, ClassName.class);
2.Use ORM such as hibernate to store Object in relational database.