I am having issues parsing this json data there is a total of 2 records in "orders" and I need to retrieve data based on
order 1 and order 2 with also of each item in "orders.order_items"
Any help would be great, it's stressing me out...
{
"status": "success",
"execution_time": "0.0304 seconds",
"total_records": 2,
"records_returned": 2,
"offset": 0,
"limit": 150,
"orders": [{
"id": "305954583",
"email": "email#gmail.com",
"date_added": "2022-03-16 20:42:44",
"date_updated": "2022-03-16 20:43:12",
"checkout_data": [],
"order_metadata": [],
"discount_list": [],
"order_notes": [],
"order_items": [{
"id": "163220786",
"name": "099922511015",
"price": 5,
"quantity": 3,
"weight": 0,
"code": "099922511015",
"delivery_type": "ship",
"category_code": "",
"fulfillment_method": "",
"variation_list": [],
"metadata": []
}],
"order_shipments": []
}, {
"id": "170951391",
"email": "email2#gmail.com",
"date_added": "2021-04-27 22:50:11",
"date_updated": "2022-03-17 02:38:43",
"checkout_data": [],
"order_metadata": [],
"discount_list": [],
"order_notes": [{
"date_added": "2022-03-17 02:38:43",
"username": "username",
"content": "testing notes"
}],
"order_items": [{
"id": "112184373",
"name": "COUNTER",
"price": 1,
"quantity": 1,
"weight": 0.25,
"code": "COUNTER",
"delivery_type": "ship",
"category_code": "",
"fulfillment_method": "",
"variation_list": [],
"metadata": []
}],
"order_shipments": []
}]
}
Currently, this is how I have it
for i in 1..2 loop
dbms_output.put_line('Order #: '||json_ext.get_string(l_json, 'orders['||i||'].id'));
temp := json_list(l_json.get('orders['||i||'].order_items'));
dbms_output.put_line(temp.get_string);
end loop;
You can use:
DECLARE
obj pljson := pljson(
'{
"status": "success",
"execution_time": "0.0304 seconds",
"total_records": 2,
"records_returned": 2,
"offset": 0,
"limit": 150,
"orders": [{
"id": "305954583",
"email": "email#gmail.com",
"date_added": "2022-03-16 20:42:44",
"date_updated": "2022-03-16 20:43:12",
"checkout_data": [],
"order_metadata": [],
"discount_list": [],
"order_notes": [],
"order_items": [{
"id": "163220786",
"name": "099922511015",
"price": 5,
"quantity": 3,
"weight": 0,
"code": "099922511015",
"delivery_type": "ship",
"category_code": "",
"fulfillment_method": "",
"variation_list": [],
"metadata": []
}],
"order_shipments": []
}, {
"id": "170951391",
"email": "email2#gmail.com",
"date_added": "2021-04-27 22:50:11",
"date_updated": "2022-03-17 02:38:43",
"checkout_data": [],
"order_metadata": [],
"discount_list": [],
"order_notes": [{
"date_added": "2022-03-17 02:38:43",
"username": "username",
"content": "testing notes"
}],
"order_items": [{
"id": "112184373",
"name": "COUNTER",
"price": 1,
"quantity": 1,
"weight": 0.25,
"code": "COUNTER",
"delivery_type": "ship",
"category_code": "",
"fulfillment_method": "",
"variation_list": [],
"metadata": []
}],
"order_shipments": []
}]
}'
);
v_order_list pljson_list;
v_order pljson;
v_order_items pljson_list;
v_item pljson;
BEGIN
v_order_list := pljson_ext.get_json_list( obj, 'orders');
FOR i IN 1 .. v_order_list.COUNT() LOOP
v_order := TREAT(v_order_list.get(i).get_element() AS pljson);
DBMS_OUTPUT.PUT_LINE('Order id: ' || v_order.get_string('id'));
v_order_items := TREAT(v_order.get('order_items').get_element() AS pljson_list);
FOR j IN 1 .. v_order_items.COUNT() LOOP
v_item := TREAT(v_order_items.get(j).get_element() AS pljson);
DBMS_OUTPUT.PUT_LINE(' Order item id: ' || v_item.get_string('id'));
END LOOP;
END LOOP;
END;
/
Which outputs:
Order id: 305954583
Order item id: 163220786
Order id: 170951391
Order item id: 112184373
db<>fiddle here
Related
I am all authenticated, and send this request to https://api.ecobee.com/1/thermostat:
{"selection":{"selectionType":"registered","selectonMatch":""},"functions":[{"type":"setHold","params":{"holdType":"indefinite","heatHoldTemp":716,"coolHoldTemp":716}}]}
I get as answer:
{
"page": {
"page": 1,
"totalPages": 1,
"pageSize": 1,
"total": 1
},
"thermostatList": [
{
"identifier": "--hidden--",
"name": "Thermostat",
"thermostatRev": "230212020022",
"isRegistered": true,
"modelNumber": "nikeSmart",
"brand": "ecobee",
"features": "Home,HomeKit",
"lastModified": "2023-02-12 02:00:22",
"thermostatTime": "2023-02-13 11:36:30",
"utcTime": "2023-02-13 16:36:30"
}
],
"status": {
"code": 0,
"message": ""
}
}
But there is no Events in my thermostat:
"events": [
{
"type": "template",
"name": "_Default_",
"running": false,
"startDate": "2037-01-01",
"startTime": "01:01:01",
"endDate": "2037-01-01",
"endTime": "02:01:01",
"isOccupied": false,
"isCoolOff": false,
"isHeatOff": false,
"coolHoldTemp": 788,
"heatHoldTemp": 644,
"fan": "auto",
"vent": "off",
"ventilatorMinOnTime": 5,
"isOptional": true,
"isTemperatureRelative": false,
"coolRelativeTemp": 40,
"heatRelativeTemp": 40,
"isTemperatureAbsolute": true,
"dutyCyclePercentage": 255,
"fanMinOnTime": 20,
"occupiedSensorActive": false,
"unoccupiedSensorActive": false,
"drRampUpTemp": 0,
"drRampUpTime": 3600,
"linkRef": "",
"holdClimateRef": "",
"fanSpeed": "low"
}
]
I am expecting, following the guide, that a Hold event is present. I do not see either a change on my thermostat UI.
Found it.
I was using HTTP GET instead of POST.
There was some typos in my JSON (selecton)
I was appending payload to URL, not as POST payload.
I have multiple requests in the same thread group and i need to pass 18 users to the 2 game id's (9 users to each gameID) and i am using counter element to create different users and gameID's.
Login Request:
42[
"get_login",
{
"uid": "EiNjkkkxgqq1ClN7gwzJEBK5XPhYKsG5",
"key": "AUEEW891WL",
"socketId":"AvKjxCGPLzgvqGxzAAb-",
"username": "",
"avatar": "",
"language": "en",
"playerMove": "",
"joinGame": "",
"replay": 0,
"gameID": 0,
"gameNo": 0,
"data": "&email=Nov${counter}#gmail.com&password=poker",
"players": 0,
"level": "",
"lastAction": "",
"game": "",
"playMoney": 1,
"role": ""
}
]
Response:
42[
"gotLogin",
{
"response": {
"playerId": 24441,
"totalWin": 0,
"points": 0,
"playerName": "672319400464",
"displayName": "DEC65",
"playerRank": "Amateur",
"playerBank": "11K",
"playerBankAmount": 11000,
"playerAvatar": "avatar1.jpg",
"playerEmail": "Nov65#gmail.com",
"playerLevel": 1,
"playerLevelStr": "Lvl. 1",
"playerLevelPrg": 0,
"playerLevelPoints": 100,
"playerGold": 0,
"playerDealerId": 1,
"playerFbId": "",
"loadVocab": "",
"dailyBonus": 0,
"token": "37333e039503825fded65f7714f04741688af294ff0a32a7c676f5c366e193de"
}
}
]
Create Game
Request:
42[
"create_game",
{
"uid": "Esdv7CHkwo1ATMfvY6NcWBTM5YB4d3nj",
"key": "AUEEW891WL",
"socketId":"AvKjxCGPLzgvqGxzAAb-",
"username": "611839990703",
"avatar": "avatar17.jpg",
"language": "en",
"playerMove": "",
"joinGame": "",
"replay": 0,
"gameID": 0,
"gameNo": 0,
"data": "&gameID=undefined&game=texas&playMoney=1&gameStyle=private-cashgame&tableName=TableOct${counter}&rakeRate=0&speed=60&sb=10&bb=20&tablelow=100&tablelimit=1000&videorequired=false&username=611839990703",
"players": 0,
"level": 347,
"lastAction": "",
"game": "",
"playMoney": 1,
"role": "1",
"token":"84d26de7404377dfa0ade2ff74676fd901852e19100068d43ac8a8d449f49a1c",
"playerId":"23910",
"displayName": "p10"
}
]
Response:
42[
"createGameRsp",
{
"response": {
"title": "Create Successful",
"result": "TableOct2 was successfully created. \n GameID: 630 \n Password: ",
"error": "",
"game": "texas",
"gameID": 630
}
}
]
Join Game:
Request:
42[
"get_joingame",
{
"uid": "Esdv7CHkwo1ATMfvY6NcWBTM5YB4d3nj",
"key": "AUEEW891WL",
"socketId":"AvKjxCGPLzgvqGxzAAb-",
"username":${userName}",
"avatar": "avatar17.jpg",
"language": "en",
"playerMove": "",
"joinGame": "",
"replay": 0,
"gameID":"${gameID}",
"gameNo": 0,
"data": "&seat=${counter2}&buyin=500&privateTable=2&clubId=0",
"players": 0,
"level": 347,
"lastAction": "ep.playNow",
"game": "texas",
"playMoney": 1,
"role": "1",
"playerId":"${playerId}",
"displayName": "p10",
"seat":${counter2}
}
]
Response:
42[
"gotJoinGame",
{
"game": "texas",
"gameID": "630",
"response": {
"error": ""
}
}
]
Right now i am able to pass one game id to only one user. But i need to pass one game id to 9 users. How is it possible?
As per JMeter documentation on variables:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads
So if you extract the gameID by one thread (virtual user) - it will be available only to this thread. If you want to use the value by other virtual user(s) - you need to convert it into a JMeter Property via __setProperty() function or suitable JSR223 Test Element
If you have 2 groups of users you can assign one gameID to users with even thread number and the other to odd users.
More information: Using JMeter Variables With Multiple Thread Groups
I see that jq can calculate addition as simply as jq 'map(.duration) | add' but I've got a more complex command and I can't figure out how to perform this add at the end of it.
I'm starting with data like this:
{
"object": "list",
"data": [
{
"id": "in_1HW85aFGUwFHXzvl8wJbW7V7",
"object": "invoice",
"account_country": "US",
"customer_name": "clientOne",
"date": 1601244686,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 49500
},
{
"id": "in_1HJlIZFGUwFHXzvlWqhegRkf",
"object": "invoice",
"account_country": "US",
"customer_name": "clientTwo",
"date": 1598297143,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 51000
},
{
"id": "in_1HJkg5FGUwFHXzvlYp2uC63C",
"object": "invoice",
"account_country": "US",
"customer_name": "clientThree",
"date": 1598294757,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 57000
},
{
"id": "in_1H8B0pFGUwFHXzvlU6nrOm6I",
"object": "invoice",
"account_country": "US",
"customer_name": "clientThree",
"date": 1595536051,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 20000
}
],
"has_more": true,
"url": "/v1/invoices"
}
and my jq command looks like:
cat example-data.json |
jq -C '[.data[]
| {invoice_id: .id, client: .customer_name, date: .date | strftime("%Y-%m-%d"), amount: .total, status: .status}
| .amount = "$" + (.amount/100|tostring)]
| sort_by(.date)'
which nicely gives me output like:
[
{
"invoice_id": "in_1H8B0pFGUwFHXzvlU6nrOm6I",
"client": "clientThree",
"date": "2020-07-23",
"amount": "$200",
"status": "paid"
},
{
"invoice_id": "in_1HJlIZFGUwFHXzvlWqhegRkf",
"client": "clientTwo",
"date": "2020-08-24",
"amount": "$510",
"status": "paid"
},
{
"invoice_id": "in_1HJkg5FGUwFHXzvlYp2uC63C",
"client": "clientThree",
"date": "2020-08-24",
"amount": "$570",
"status": "paid"
},
{
"invoice_id": "in_1HW85aFGUwFHXzvl8wJbW7V7",
"client": "clientOne",
"date": "2020-09-27",
"amount": "$495",
"status": "paid"
}
]
and I want to add a sum/total at the end of that, something like Total: $1775, so that the entire output would look like this:
[
{
"invoice_id": "in_1H8B0pFGUwFHXzvlU6nrOm6I",
"client": "clientThree",
"date": "2020-07-23",
"amount": "$200",
"status": "paid"
},
{
"invoice_id": "in_1HJlIZFGUwFHXzvlWqhegRkf",
"client": "clientTwo",
"date": "2020-08-24",
"amount": "$510",
"status": "paid"
},
{
"invoice_id": "in_1HJkg5FGUwFHXzvlYp2uC63C",
"client": "clientThree",
"date": "2020-08-24",
"amount": "$570",
"status": "paid"
},
{
"invoice_id": "in_1HW85aFGUwFHXzvl8wJbW7V7",
"client": "clientOne",
"date": "2020-09-27",
"amount": "$495",
"status": "paid"
}
]
Total: $1775
Is there a neat/tidy way to enhance this jq command to achieve this?
Or even, since I'm invoking this in a shell script, a dirty/ugly way with bash?
If any of your output is going to be raw, you need to pass -r; it'll just be ignored for data items that aren't strings.
Anyhow -- if you write (expr1, expr2), then your input will be passed through both expressions. Thus:
jq -Cr '
([.data[]
| {invoice_id: .id,
client: .customer_name,
date: .date | strftime("%Y-%m-%d"),
amount: .total,
status: .status}
| .amount = "$" + (.amount/100|tostring)
] | sort_by(.date)),
"Total: $\([.data[] | .total] | add | . / 100)"
'
In case you decide after all to emit valid JSON, here is a modular answer to the question that makes it easy to formulate alternative approaches, and which postpones the conversion of .amount to dollars for efficiency:
def todollar:
"$" + tostring;
def json:
[.data[]
| {invoice_id: .id,
client: .customer_name,
date: .date | strftime("%Y-%m-%d"),
amount: (.total/100),
status: .status} ]
| sort_by(.date) ;
json
| map_values(.amount |= todollar),
"Total: " + (map(.amount) | add | todollar)
As noted elsewhere, you will probably want to use the -r command-line option.
I have a problem in repeated grid, I have a drop-down list where the users will choose what model they want.
Then I also have a JSON array which contains the model and other description of different cars.
How can I auto fill the appropriate JSON value to textField according to the chosen value in the drop-down list?
Like for example: The user chose the model Toyota, only the Toyota car model present in the JSON will be displayed at textField.
The form I've created is available at https://demo.orbeon.com/demo/fr/orbeon/builder/edit/3b1ebd5340007f245b34ccd468c36c188b376bd6. And here is the JSON:
{
"corppassUser": {
"corppassData": null,
"corppassEntity": {
"primaryActiviyDesc": "Marine insurance ",
"companyType": "A1",
"corppassPreviousNames": [],
"entityType": "LC",
"primaryActivityCode": "65121",
"businessExpiryDate": "",
"secondaryActivityCode": "93202",
"corppassShareholders": [
{
"allocation": 20000,
"personRef": {
"personName": "ANDY",
"nationality": "SG",
"id": 8,
"idno": "S6001111A"
},
"currency": "SGD",
"id": 3,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "TIMOTHY TAN",
"nationality": "SP",
"id": 6,
"idno": "S1112374E "
},
"currency": "SGD",
"id": 1,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "CLARISSA LIN",
"nationality": "SG",
"id": 7,
"idno": "S3212386E"
},
"currency": "SGD",
"id": 2,
"entityRef": null,
"category": "1",
"shareType": "1"
}
],
"uen": "T15LP0005A"
},
"id": 1
}
}
Yammer Activity Stream is available at:
https://www.yammer.com/api/v1/streams/activities.json?access_token=
This successfully results in all the recent activities like:
{
"items": [
{
"id": "/users/www.yammer.com-341514-1508953644/rollups/45191477209921-45191477209921",
"unseen": true,
"icon": "/images/notifications/page_add.png",
"icon_name": null,
"category": "file-create",
"message": "[[user:1508783078]] uploaded [[uploaded_file:24511980]].",
"heading": "",
"created_at": "2014/10/02 07:07:42 +0000",
"objects": [],
"actions": [],
"subject": {
"type": "uploaded_file",
"id": 24511980
},
"meta": null,
"client_type": "unknown",
"client_url": "https://www.yammer.com",
"client_icon": "https://mug0.assets-yammer.com/mugshot/images/16x16/3rd_party.png",
"client_large_icon": "https://mug0.assets-yammer.com/mugshot/images/75x75/3rd_party.png",
"image": "https://mug0.assets-yammer.com/mugshot/images/48x48/no_photo.png",
"third_party": false
},
{
"id": "/users/www.yammer.com-341514-1508953644/rollups/45191475863746-45191475863746",
"unseen": true,
"icon": "/images/notifications/page_add.png",
"icon_name": "page",
"category": "file-download",
"message": "[[user:1508783078]] downloaded [[uploaded_file:24373320]] from the [[group:3455089]] group.",
"heading": "",
"created_at": "2014/10/02 07:07:00 +0000",
"objects": [
{
"id": 24373320,
"type": "uploaded_file"
}
],
"actions": [],
"subject": {
"type": "uploaded_file",
"id": 24373320
},
"meta": null,
"client_type": "unknown",
"client_url": "https://www.yammer.com",
"client_icon": "https://mug0.assets-yammer.com/mugshot/images/16x16/3rd_party.png",
"client_large_icon": "https://mug0.assets-yammer.com/mugshot/images/75x75/3rd_party.png",
"image": "https://mug0.assets-yammer.com/mugshot/images/48x48/no_photo.png",
"third_party": false
},
]}
QUESTION:
I am trying to get all the recent activities after a certain time-stamp or after a certain offset. Is there any query parameter for that?
this is
older_than="/users/www.yammer.com-341514-1508953644/rollups/45191475863746-45191475863746"
that would return all the activities older than the last activities you shew in your sample return value