How to solve Cannot cast object '0.0' with class 'java.lang.Double' to class 'org.json.JSONObject' - json

This is some part of my input json :-
"orderLine": {
"agreementHeaderId": [
null
],
"agreementNumber": [
null
],
"customerProductId": null,
"displayLineNumber": "2",
"estimateFulfillmentCost": 9.97,
"extendedAmount": null,
"fulfilledQuantity": null,
"fulfillToleranceAbove": null,
"inventoryOrganizationCode": "107",
"inventoryOrganizationId": "107",
"jobName": null,
"orderedQuantity": 1.0,
"orderedUom": null,
"origSystemDocumentLineReference": "2",
"paymentTerms": "CASH ON DEMAND",
"paymentTermsCode": "COD",
"productId": "4065412*107",
"productNumber": "4065412",
"productDescription": "20 DFU AAV W/ 1-1/2-2 PVC ADPT",
"purchasingUom": null,
"quantityPerModel": 0.0,
"requestedShipDate": "2022-12-19T05:00:00.000Z",
"requestedSupplierNumber": null,
"requisitionInventoryOrganizationId": "107",
"rmaDeliveredQuantity": null,
"scheduleShipDate": null,
"shippedQuantity": 1.0,
"shippingCarrier": "OT",
"shippingInstructions": null,
"shippingMode": "OUR TRUCK",
"shippingModeCode": "OT",
"subInventory": null,
"transactionLineTypeCode": null,
"transactionCategoryCode": null,
"transactionLineType": "MP",
"unitListPrice": 33.23,
"unitQuantity": 1.0,
"unitSellingPrice": 44.0,
Few values are double type not string
So, while giving this JSONObject oldQty = (JSONObject) orderLine.get("orderedQuantity")
I'm getting Cannot cast object '0.0' with class 'java.lang.Double' to class 'org.json.JSONObject' this error

Related

NestJs TypeOrm loadRelationCountAndMap apply order by operation on it

I am new in NestJs TypeORM and I tried to get the count only from the relation table using loadRelationCountAndMap method and now I need a fetuare to change the order of that count ASC or DESC but when I tried the orderBy method it will return me unknow colunm name.
Here is my query
await this.userRepository
.createQueryBuilder('user')
.leftJoinAndSelect('user.roles', 'roles')
.loadRelationCountAndMap('user.postCount', 'user.post', 'post', qb =>
qb.where('post.type =:type', { type: 'post' }),)
.loadRelationCountAndMap('user.userSpotCount', 'user.spot', 'spot')
.loadRelationCountAndMap(
'user.itineraryCount',
'user.post',
'post',
qb => qb.where('post.type =:type', { type: 'itinerary' }),)
.where('roles.name = :name', { name: request.user_type })
.orderBy('userSpotCount', 'ASC');
and the output is without orderBy method
[{
"id": xxxxx,
"name": "xxxx xxxx",
"email": "xxxx.xxxx#xxxx.xxx",
"facebook_id": null,
"google_id": null,
"apple_id": null,
"is_email_verifie": null,
"is_phone_verifie": null,
"created_at": "2022-06-06T23:38:04.000Z",
"updated_at": "2022-06-06T23:38:04.000Z",
"phone": "1234567890",
"token": null,
"profile_pic": "",
"status": "pending",
"email_token": null,
"deleted_at": null,
"latitude": "26.78965",
"longitude": "93.78965",
"is_public": null,
"basedIn": null,
"visit_place": null,
"visit_place_lat": null,
"visit_place_long": null,
"notification_flag": "on",
"location": "abc, xyz, pqr",
"country_code": null,
"home_key": 1,
"postCount": 0,
"userSpotCount": 5,
"itineraryCount": 0
},
{
"id": xxxxx,
"name": "xxxx xxxx",
"email": "xxxx.xxxx#xxxx.xxx",
"facebook_id": null,
"google_id": null,
"apple_id": null,
"is_email_verifie": null,
"is_phone_verifie": null,
"created_at": "2022-06-06T23:38:04.000Z",
"updated_at": "2022-06-06T23:38:04.000Z",
"phone": "1234567890",
"token": null,
"profile_pic": "",
"status": "pending",
"email_token": null,
"deleted_at": null,
"latitude": "26.78965",
"longitude": "93.78965",
"is_public": null,
"basedIn": null,
"visit_place": null,
"visit_place_lat": null,
"visit_place_long": null,
"notification_flag": "on",
"location": "abc, xyz, pqr",
"country_code": null,
"home_key": 1,
"postCount": 0,
"userSpotCount": 1,
"itineraryCount": 0
}
]
I need this output as per the order by ASC/DESC

How to filter array of elements in JMESPath with Azure CLI

I am total newbie in JMESPath parsing.
az network lb inbound-nat-rule list --resource-group MYRG --lb-name MYLB is returning below output and I would like filter only backendIpConfiguration.id and backendPort in the response.
Below response in have array of elements.
[
{
"backendIpConfiguration": {
"applicationGatewayBackendAddressPools": null,
"applicationSecurityGroups": null,
"etag": null,
"gatewayLoadBalancer": null,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"loadBalancerBackendAddressPools": null,
"loadBalancerInboundNatRules": null,
"name": null,
"primary": null,
"privateIpAddress": null,
"privateIpAddressVersion": null,
"privateIpAllocationMethod": null,
"privateLinkConnectionProperties": null,
"provisioningState": null,
"publicIpAddress": null,
"resourceGroup": "MYRG01",
"subnet": null,
"type": null,
"virtualNetworkTaps": null
},
"backendPort": 1367,
"enableFloatingIp": false,
"enableTcpReset": false,
"etag": "W/\"XXXXX-1173-49ad-8d1f-40347c00d88a\"",
"frontendIpConfiguration": {
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"resourceGroup": "MYRG01"
},
"frontendPort": 1367,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"idleTimeoutInMinutes": 5,
"name": "rule1",
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "MYRG01",
"type": "Microsoft.Network/loadBalancers/inboundNatRules"
},
{
"backendIpConfiguration": {
"applicationGatewayBackendAddressPools": null,
"applicationSecurityGroups": null,
"etag": null,
"gatewayLoadBalancer": null,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"loadBalancerBackendAddressPools": null,
"loadBalancerInboundNatRules": null,
"name": null,
"primary": null,
"privateIpAddress": null,
"privateIpAddressVersion": null,
"privateIpAllocationMethod": null,
"privateLinkConnectionProperties": null,
"provisioningState": null,
"publicIpAddress": null,
"resourceGroup": "MYRG02",
"subnet": null,
"type": null,
"virtualNetworkTaps": null
},
"backendPort": 3006,
"enableFloatingIp": false,
"enableTcpReset": false,
"etag": "W/\"XXXX-1173-49ad-8d1f-40347c00d88a\"",
"frontendIpConfiguration": {
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"resourceGroup": "MYRG02"
},
"frontendPort": 3006,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"idleTimeoutInMinutes": 5,
"name": "rule2",
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "MYRG02",
"type": "Microsoft.Network/loadBalancers/inboundNatRules"
}
]
Filtering in JMESPath is quite simple, and the documentation is pretty straight forward for filters and multiselect hashes.
In here, a simple query like:
[].{backendIpConfigurationId: backendIpConfiguration.id, backendPort: backendPort}
Will give you the filtered JSON:
[
{
"backendIpConfigurationId": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"backendPort": 1367
},
{
"backendIpConfigurationId": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"backendPort": 3006
}
]
Containing only the informations you are looking for.

Get N number of values from object with jq

I'm trying to retrieve a given number of values from the following json object (just used 2 for brevity):
[
{
"content": null,
"deleted": false,
"metadata": null,
"name": "name/windows-2016-osDisk.170b8936-d66d-4139-a409-26f4e9d354fe.vhd",
"properties": {
"appendBlobCommittedBlockCount": null,
"blobTier": "P10",
"blobTierChangeTime": null,
"blobTierInferred": true,
"blobType": "PageBlob",
"contentLength": 136367309312,
"contentRange": null,
"contentSettings": {
"cacheControl": null,
"contentDisposition": null,
"contentEncoding": null,
"contentLanguage": null,
"contentMd5": "-0q970378r08==",
"contentType": "application/octet-stream"
},
"copy": {
"completionTime": null,
"id": null,
"progress": null,
"source": null,
"status": null,
"statusDescription": null
},
"creationTime": "2019-11-21T08:34:33+00:00",
"deletedTime": null,
"etag": "0237502375",
"lastModified": "2019-11-21T08:34:33+00:00",
"lease": {
"duration": null,
"state": "available",
"status": "unlocked"
},
"pageBlobSequenceNumber": null,
"remainingRetentionDays": null,
"sequenceNumber": 1,
"serverEncrypted": true
},
"snapshot": null
},
{
"content": null,
"deleted": false,
"metadata": null,
"name": "name/windows-2019-osDisk.f122fb3c-0edb-42a8-b98c-56657b447f15.vhd",
"properties": {
"appendBlobCommittedBlockCount": null,
"blobTier": "P10",
"blobTierChangeTime": null,
"blobTierInferred": true,
"blobType": "PageBlob",
"contentLength": 136367309312,
"contentRange": null,
"contentSettings": {
"cacheControl": null,
"contentDisposition": null,
"contentEncoding": null,
"contentLanguage": null,
"contentMd5": "0237502375/hKOg==",
"contentType": "application/octet-stream"
},
"copy": {
"completionTime": null,
"id": null,
"progress": null,
"source": null,
"status": null,
"statusDescription": null
},
"creationTime": "2019-11-21T08:35:03+00:00",
"deletedTime": null,
"etag": "20397520i3h523",
"lastModified": "2019-11-21T08:35:03+00:00",
"lease": {
"duration": null,
"state": "available",
"status": "unlocked"
},
"pageBlobSequenceNumber": null,
"remainingRetentionDays": null,
"sequenceNumber": 1,
"serverEncrypted": true
},
"snapshot": null
}
]
I sort this on creationTime in jq like so: jq 'sort_by(.properties.creationTime)' When I pipe this through | .[].name making jq 'sort_by(.properties.creationTime) | .[].name I get a sorted list of the names.
My question is: How can I pass an integer to this command and remove these many names, starting from the most recent created (bottom)?
following
https://stedolan.github.io/jq/manual/v1.6/#Builtinoperatorsandfunctions
slicing should work:
jq 'sort_by(.properties.creationTime) | .[-1:]'
The answer I've used is the following:
jq 'sort_by(.properties.creationTime) | .[-4:] | .[].name'
Where -4 is the amount of names to display starting from the bottom.

How to compare rows from JSON file in angular?

I have this items in a JSON file that I need to compare wherever I have Curr or Prev values and compare if they are equals. this algorithm is with angular 5 but I'm being unable to do this, I did the load function with httpClient
Example :
[{
"id": 1,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A251000.01",
"rpt": "D70",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}, {
"id": 2,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A270028.01",
"rpt": "E15",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}]
this should be with using lodash.
i assume your want something like this
for each object in your array
filter keys that end with "Curr"
for each get Prev property
compare it with curr property
let obj = [{
"id": 1,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A251000.01",
"rpt": "D70",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}, {
"id": 2,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A270028.01",
"rpt": "E15",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}];
obj.forEach(x=>{
Object.keys(x)
.filter(y=>y.endsWith("Curr"))
.forEach(y=>{
let prevProp = y.replace("Curr", "Prev")
console.log(y, x[y]);
console.log(prevProp ,x[prevProp ]);
if(x[y]===x[prevProp ]){
//equal
}else{
//not equal
}
})
})
you could use lodash's _.forEach, _.Keys, _.filter but i think there is not much point on this.

How to convert few columns of pandas dataframe into JSON record within another record?

So I am trying to convert a pandas Dataframe with 12+ columns into corresponding JSON Record. I'm able to get it. However, I want few columns of the frame to be a subrecord of a new column. How this can be achieved.?
{
"ADRNR": 2692629,
"AlertID": "",
"AlertTimestamp": "14-12-2015 14:44:14",
"BANKL": null,
"BANKN": null,
"BANKS": "nan",
"BEGRU": "NPIV",
"BUKRS": "2646",
"C_Block": "No",
"KOINH": null,
"LAND1": "US",
"LOEVM_x": null,
"LOEVM_y": null,
"MasterDataID": "10099",
"MasterDataType": "Vendor",
"NAME1": "LEGAL",
"NODEL_x": null,
"NODEL_y": null,
"ORT01": null,
"OtherData": null,
"PSTLZ": null,
"RuleID": "Rule3",
"RuleName": "Vendor and Bank Country is Different",
"STCD1": null,
"STCD2": null,
"STCEG": null,
"STRAS": null,
"TELF1": null
}
The above JSON is what I Get. But I want the following structure. Kindly guide me.
{
"RuleID": "Rule3",
"RuleName": "Vendor and Bank Country is Different",
"AlertID": "",
"AlertTimestamp": "14-12-2015 14:44:14",
"MasterDataID": "10099",
"MasterDataType": "Vendor",
"OtherData": {
"BANKL": null,
"BANKN": null,
"BANKS": "nan",
"BEGRU": "NPIV",
"BUKRS": "2646",
"C_Block": "No",
"KOINH": null,
"LAND1": "US",
"LOEVM_x": null,
"LOEVM_y": null,
"NAME1": "LEGAL",
"NODEL_x": null,
"NODEL_y": null,
"ORT01": null,
"PSTLZ": null,
"ADRNR": 2692629,
"STCD1": null,
"STCD2": null,
"STCEG": null,
"STRAS": null,
"TELF1": null
}
}
Edit : Flg is my code
Final_Table['AlertID'] = ''
Final_Table['AlertTimestamp'] = datetime.now().strftime('%d-%m-%Y %H:%M:%S')
Final_Table['MasterDataType'] = 'Vendor'
Final_Table['RuleID'] = 'Rule3'
Final_Table['RuleName'] = 'Vendor and Bank Country is Different'
Final_Table = Final_Table.rename(columns={'LIFNR': 'MasterDataID'})
Result = Final_Table[Final_Table['BANKS'] != Final_Table['LAND1']]
Result['OtherData'] = np.NaN
final_result = {'alerts': json.loads(Result.to_json(orient = 'records',force_ascii = False).encode('utf8'))}
result = {'results': final_result}
with open('output_Rule3.json', 'w') as outfile:
json.dump(result, outfile, indent = 5, sort_keys = True)
log.info("Rule3 : Execution Successful")
Rather than within pandas, I would modify the json output.
Starting with your json data
print(json.dumps(data, indent=4, sort_keys=True))
[
{
"ADRNR": 2692629,
"AlertID": "",
"AlertTimestamp": "14-12-2015 14:44:14",
"BANKL": null,
"BANKN": null,
"BANKS": "nan",
"BEGRU": "NPIV",
"BUKRS": "2646",
"C_Block": "No",
"KOINH": null,
"LAND1": "US",
"LOEVM_x": null,
"LOEVM_y": null,
"MasterDataID": "10099",
"MasterDataType": "Vendor",
"NAME1": "LEGAL",
"NODEL_x": null,
"NODEL_y": null,
"ORT01": null,
"OtherData": null,
"PSTLZ": null,
"RuleID": "Rule3",
"RuleName": "Vendor and Bank Country is Different",
"STCD1": null,
"STCD2": null,
"STCEG": null,
"STRAS": null,
"TELF1": null
}
]
and a list of some of the columns you are interested in:
other_data = ["BANKL", "BANKN", "BANKS", "BEGRU", "BUKRS", "C_Block"]
you can modify the json directly:
for i, record in enumerate(data):
data[i]['OtherData'] = {}
for key in list(record.keys()):
if key in other_data:
data[i]['OtherData'][key] = record[key]
del data[i][key]
print(json.dumps(data, indent=4, sort_keys=True))
[
{
"ADRNR": 2692629,
"AlertID": "",
"AlertTimestamp": "14-12-2015 14:44:14",
"KOINH": null,
"LAND1": "US",
"LOEVM_x": null,
"LOEVM_y": null,
"MasterDataID": "10099",
"MasterDataType": "Vendor",
"NAME1": "LEGAL",
"NODEL_x": null,
"NODEL_y": null,
"ORT01": null,
"OtherData": {
"BANKL": null,
"BANKN": null,
"BANKS": "nan",
"BEGRU": "NPIV",
"BUKRS": "2646",
"C_Block": "No"
},
"PSTLZ": null,
"RuleID": "Rule3",
"RuleName": "Vendor and Bank Country is Different",
"STCD1": null,
"STCD2": null,
"STCEG": null,
"STRAS": null,
"TELF1": null
}
]