I want to put the JSON data into an array and fetch the data
{
"data":{
"platform":{
"id":"d0feb170-76ed-77e9-a24f-44c49397cb8f",
"version":0,
"updatedTime":1557910234867,
"dataVersion":{
"version":0,
"updatedTime":1557910234867
}
},
"machine":{
"version":44,
"updatedTime":1557910026619,
"version":{
"version":19,
"updatedTime":1557910026619
},
"systemId":"Machine1",
"activeStatus":"true",
"settings":[
{
"protNumber":"1.2",
"proto":"TestHead2^^Adult^^Head",
"id":"21a8fbb8-40ea-4868-ae3a-ee1d130eb01b",
"name":"TestHead2",
"humanoid":"Adult",
"anatomy":"Head",
"lastUpdated":"Wed, 15 May 2019 08:47:06 GMT",
"version":0
},
{
"protNumber":"1.8",
"proto":"TestHead8^^Adult^^Head",
"id":"2a25874e-cb9f-40c1-93db-a0859b209491",
"name":"TestHead8",
"humanoid":"Adult",
"anatomy":"Head",
"lastUpdated":"Wed, 15 May 2019 08:47:06 GMT",
"version":0
},
{
"protNumber":"1.88",
"proto":"TestHead88^^Adult^^Head",
"id":"50cc13d8-6d43-4fcd-9d60-08ce4f97632d",
"name":"TestHead88",
"humanoid":"Adult",
"anatomy":"Head",
"lastUpdated":"Wed, 15 May 2019 08:47:06 GMT",
"version":0
}
],
"deviceDeviation":{
"new":9,
"deviated":0,
"newMatched":0,
"totalProtocols":3
}
}
},
"success":true,
"statusCode":200,
"errorMessage":""
}
How can I put the data in the settings into an Array and fetch them one by one?
Use JSON Extractor to fetch data:-
Below, I have created one JSON extractor config for protNumber.
Please check the variable in the results. You can use the first three variables or if you need all then use the 4th...depend on your requirement. Fetch using ${prNumVar_1},${prNumVar_2} etc
Create multiple extractor for different variables..like prot, id, name as per your requirement.
Hope this helps.
Related
I have a file filled with objects in JSON format containing an email property for thousands of users.
{
"object":"list",
"read_only":{
},
"full_access":{
"data":[
{
"id":"32923939",
"platform_id":"12313",
"name":"test",
"email":"test#example.com",
"created_date":"08 Feb 17 10:02 +0000"
},
{
"id":"135541",
"platform_id":"1234",
"name":"test",
"email":"test#example.com",
"created_date":"08 Feb 17 10:00 +0000"
},
{
"id":"484949383",
"platform_id":"494948",
"name":"test",
"email":"test#example.com",
"created_date":"08 Feb 17 08:46 +0000"
},
{
"id":"595033",
"platform_id":"test",
"name":"test",
"email":"test#example.com",
"created_date":"30 Sep 16 17:51 +0000"
}
]
},
"never_logged_in":{
}
}
The problem I am facing is that some of the objects are not formatted correctly, so I am unable to work with them in code. I am wondering if there is a way that I can search the file for a string, "email:", followed by the email address, and delete everything else. I feel like I can accomplish this using regex, to detect the email address, but I am unsure of how to do it myself.
Could anyone offer any insight or recommendations?
In Javascript, you can do something like -
var myJson = {"object":"list","read_only":{},"full_access":{"data":[{"id":"32923939","platform_id":"12313","name":"test","email":"test#example.com","created_date":"08 Feb 17 10:02 +0000"},{"id":"135541","platform_id":"1234","name":"test","email":"test#example.com","created_date":"08 Feb 17 10:00 +0000"},{"id":"484949383","platform_id":"494948","name":"test","email":"test#example.com","created_date":"08 Feb 17 08:46 +0000"},{"id":"595033","platform_id":"test","name":"test","email":"test#example.com","created_date":"30 Sep 16 17:51 +0000"}]},"never_logged_in":{}}
var result = myJson.full_access.data.filter(x=>x.email && x.email!="")
.map(x=>x.email);
console.log(result);
It will check if an element in the data property has email (.filter method), and then map out the email ids in an array.
Here's a JSFiddle link. Check the console for output.
Note : If you just want to do it as a one time activity, paste the original object you received in the Fiddle and just copy the result object from console.
Also, you can use a linter like JSONLint to check where all the JSON is breaking.
Can someone please help me with how to filter the results returned by the the query builder json servlet? The following is the json response,
{
"success":true,
"results":2,
"total":2,
"more":false,
"offset":0,
"hits":[
{
"SourceNodePath":"/content/en/events",
"Status":"COMPLETED",
"dateRequested":1492325940000,
"ContentType":"PAGE",
"SubmissionId":[
"016192"
],
"SourceLanguage":"en",
"TargetLanguages":[
"fr"
],
"dateCreated":1492191038787,
"dateReceived":1492191112322,
"Identifier":1492191038787,
"Initiator":"user",
"name":"2",
"Code":"201"
},
{
"SourceNodePath":"/content/en/toolbar",
"Status":"COMPLETED",
"dateRequested":1492325940000,
"ContentType":"PAGE",
"SubmissionId":[
"016190"
],
"SourceLanguage":"en",
"TargetLanguages":[
"de"
],
"dateCreated":1492190651609,
"dateReceived":1492190694082,
"Identifier":1492190651609,
"Initiator":"foo",
"name":"1",
"Code":"201"
}
]
}
I'm new to AEM development, is there any way to modify the QueryBuilder JSON Servlet so that it displays the results that has the "Initiator" value as, for example in this case, "user"? The "Initiator" takes the value of the username on AEM Sign In.
In your query you can define it like
property=Initiator
property.value=user
This article outlines all of the options, so take a minute to read through it:
https://docs.adobe.com/docs/en/aem/6-2/develop/search/querybuilder-api.html
I also assume you know you can build queries and see the differences in output with different parameters at this URL: /libs/cq/search/content/querydebug.html
I have json stored in table with 3 million rows.
A single row contains json in below format
[
{
"Transaction":[
{
"ProductInfo":[
{
"LINE_NO":"1",
"STOCKNO":"890725471381116060"
},
{
"LINE_NO":"2",
"STOCKNO":"890725315884216020"
}
]
}
],
"Payment":[
{
"ENTSRLNO":"1",
"DOCDT":"08/25/2016"
}
],
"Invoice":[
{
"SALES_TYPE":"Salesinvoice",
"POS_CODE":"A20",
"CUSTOMER_ID":"0919732189692",
"TRXN_TYPE":"2100",
"DOCNOPREFIX":"CM16",
"DOCNO":"1478",
"BILL_DATE":"08/25/2016 03:59:07"
}
]
}
]
I want to dump above json in three different table
ProductInfo
Payment table
Invoice
How to perform above task in a optimise way?
Well most efficient way will be to write a procedure and use open json in sql server
check below link:
https://msdn.microsoft.com/en-IN/library/dn921879.aspx
I am facing an issue in test case when i am trying to do deepEqual where i am trying to compare the exact structure of result data with sample data.
the above is my sample json data which i created with the result of the actual data.
Code:
it('comparing structures',()=>{
var result = instance.parseResponse(input,esResponse);
console.log(result);
assert.deepEqual( result, expectedJSON);
});
Here in console i am getting the result .
Taking the result i am creating the sample data .
Code :
var expectedJSON={
"response":{
"aggregate":{
"average":43.833333333333336,
"count":6,
"max":90,
"min":10,
"total":263
},
"endDate":"Tue Jul 05 2016 05:30:00 GMT+0530 (India Standard Time)",
"groupBy":"datetime",
"metricType":"distance_metric",
"quarters":[{
"aggregate":{
"average":0,
"count":undefined,
"max":0,
"min":0,
"total":0
},
"quarter":4,
"startDate":"Invalid Date"
}],
"startDate":"Tue Jan 12 2016 05:30:00 GMT+0530 (India Standard Time)",
"type":"person"
}
};
I am doing this because i need to create the exact Json structure and let anything may be the result the structure should match .
but i am getting the fail test case
deepEqual have a lot of issues and is old now. Lot of new ECMA features aren't supported either. I found this one very interesting: https://github.com/zubuzon/kewlr
When you use deepEqual it checks not only the structure of the object but also the type of object. In this case it is given by __proto__
i have testa couchbase 4 server, to store sensor measurement data.
I have following view:
function (doc, meta) {
if (doc.aks) {
emit([doc.aks, doc.timestamp], {
value: doc.value,
status: doc.status
});
}
}
Here an example document:
{
"timestamp": 1199180981,
"value": 0,
"status": 2147483650,
"aks": "BN028:H23:VS:001:Zustand"
}
I try now following query to this view:
Give me a timerange of values for a single sensor.
/_view/timeline?stale=false&startkey=["BN020:H03:ZW:102:MC_t_return",12675419334]&endkey=["BN020:H03:ZW:102:MC_t_return",13675419334]
But this will give no result.
I get an result if i jsut use startkey= or endkey= but not if i use both.
What do i wrong?
Make sure you actually have data in your bucket that would fall within your range. I used your View and your Query and received results. Your example document is not within the range, the aks is wrong and the timestamp is too early. If you add a document that is in the range you should receive it back. This one is the lower bound of your range:
{
"timestamp": 12675419334,
"value": 0,
"status": 2147483650,
"aks": "BN020:H03:ZW:102:MC_t_return"
}