How to match a json value with the jq command? - json

I have the following json data:
{
"item_i7bfe8f00": {
"id": "i7bfe8f00",
"tag": "item",
"fields": {
"img": "https://example.com",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 5,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "ALL ITEM STORE",
"title": "Xiaomi Redmi 4A Softcase Black",
"stockTip": {},
"valid": true,
"itemId": "143800088",
"operations": [
"wishlist",
"delete"
],
"sellerId": "100124080",
"price": {
"price": 3500,
"currentPrice": "Rp3.500",
"originPrice": "Rp15.000",
"promotionRatio": "-77%"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Softcase, Hitam",
"productVariant": "SO908ELAAVYY4AANID-72544754",
"brandId": "17818",
"skuId": "157608391"
},
"itemUrl": "https://example.com",
"cartItemId": 2080280320
},
"type": "biz"
},
"item_i7c09dcce": {
"id": "i7c09dcce",
"tag": "item",
"fields": {
"img": "https://example.com",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "PT. Ecart Services Indonesia",
"title": "Black",
"stockTip": {},
"valid": true,
"itemId": "345695828",
"operations": [
"wishlist",
"delete"
],
"sellerId": "100161156",
"price": {
"price": 2499000,
"currentPrice": "Rp2.499.000"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Hitam",
"productVariant": "345695828_ID-359330058",
"brandId": "21734",
"skuId": "359330058"
},
"itemUrl": "https://example.com",
"cartItemId": 2081021134
},
"type": "biz"
}
}
and I want to show the object that only has "cartItemId": 2081021134 so the end result should look like this:
{
"item_i7c09dcce": {
"id": "i7c09dcce",
"tag": "item",
"fields": {
"img": "https://example.com",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "PT. Ecart Services Indonesia",
"title": "Black",
"stockTip": {},
"valid": true,
"itemId": "345695828",
"operations": [
"wishlist",
"delete"
],
"sellerId": "100161156",
"price": {
"price": 2499000,
"currentPrice": "Rp2.499.000"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Hitam",
"productVariant": "345695828_ID-359330058",
"brandId": "21734",
"skuId": "359330058"
},
"itemUrl": "https://example.com",
"cartItemId": 2081021134
},
"type": "biz"
}
}
This is what I have tried so far :
jq 'select(.cartItemId==2081021134)' input.json
but it returns nothing, how should I fix it ?

You have to go digging a little deeper. Feed the values of the object to select, and check .fields.cartItemId, not just .cartItemId.
jq '.[] | select(.fields.cartItemId == 2081021134)' input.json

This produces the desired output. Using with_entries makes it easy to retain the keys.
with_entries( if .value | has("fields")
then select(.value.fields.cartItemId == 2081021134)
else . end)

Related

How can I extract json data from snowflake

I'm working with Snowflake, and have a batch of JSON data in a variant datatype. I'm going to paste just the first entry (I hope) out of megabytes of data.
I need to figure out the SQL to extract the data elements from it.
This query:
SELECT
src:value::string AS valuest,
src:value:evaluation_forms as evaluation_forms,
src:value:evaluation_forms:evaluations as evaluations,
src:value:evaluation_forms:evaluations:channel_meta as channel_meta,
src:value:evaluations:channel_meta:agent_first_name as agent_first_name
FROM stage.intuit_quality_raw_table
retrieves JSON data in valuest, JSON data in evaluation_forms, and nulls in evaluations, channel_meta, and agent_first_name.
I suspect that that is because of the '[' characters that occur in from of the evaluations and channel_meta entries, but I just don't know how to deal with that sort of data.
I aplogize the being so long. The first entry is something over 300 lines long, and I'm afraid to try to shorten it because I fear that I will delete something important. I've already added the ending batch of stuff, which I'm also afraid that I might have messed up.
Anyway, here it is:
{"value":
{"evaluation_forms":
[ {"evaluations":
[ {"channel_meta":
{"after_call_work_time": [],
"agent_first_name": ["KATRINA"],
"agent_hung_up": [],
"agent_last_name": ["COX"],
"agent_unique_id": ["LO_00130604"],
"agent_username": [],
"alternate_call_id": [],
"audio_file_name": ["b161aa50-cda9-42e2-ad16-117a9cf08b92.wav"],
"call_direction": ["INBOUND"],
"call_id": ["b161aa50-cda9-42e2-ad16-117a9cf08b92"],
"channel_type": "Call",
"customer_id": [],
"customer_segment": [],
"disposition": [],
"disposition_time": [],
"end_at": ["2023-01-24 12:00:00"],
"file_location": ["blank"],
"handle_time": ["1824"],
"hold_time": [],
"how_call_ended": ["Transferred"],
"how_call_originated": [],
"id": "3cb5a3e5-0ab8-4a38-9f6b-4ab3b2e24351",
"ivr_options": [],
"line": ["Intuit"],
"notes": [],
"queue": ["Product Support"],
"queue_time": [],
"start_at": ["2023-01-24 12:00:00"]
"subqueue": [ "Product Support - Desktop" ],
"supplemental_field_1": ["Expert Service Score: 3"],
"supplemental_field_10": [],
"supplemental_field_2": ["Derived TNPS Score: 0"],
"supplemental_field_3": [],
"supplemental_field_4": [],
"supplemental_field_5": [],
"supplemental_field_6": [],
"supplemental_field_7": [],
"supplemental_field_8": [],
"supplemental_field_9": [],
"talk_time": ["78"],
"team_id": [],
"times_held": ["2"],
"total_time": []
},
"evaluation_list": [
{"evaluation_meta":
{"ack_info":
{"ack_init_time":
null,
"ack_status": "NOT_INITIATED",
"ack_time": null,
"dispute_raised_at": null,
"dispute_raised_by_email": null,
"dispute_resolved_at": null,
"dispute_resolved_by_email": null
},
"agent_email": "lo_00130604#liveopsnation.com",
"agent_id": "63d77af042a6982e25008bf3",
"agent_name": "KATRINA COX",
"agent_status": "ACTIVE",
"created_at": "2023-02-06T02:16:53.637Z",
"evaluation_purpose": null,
"evaluation_type": "Manual",
"evaluator_email": "info#ara-gs.com",
"evaluator_id":"63cb37e42db1035ae08285d1",
"evaluator_name": "RAMON CARPIO JR�",
"evaluator_status": "ACTIVE",
"id": "63e06221ea5e4c7202572252",
"modified_at": "2023-02-06T02:17:35.229Z",
"status": "EDITED"
},
"response": {
"comment": "",
"sections": [
{
"id": "3fe2faeb-e8bc-4a16-9fd1-49166a3eed4d",
"questions": [
{
"comment": "",
"fail": false,
"id": "4c057d99-aae7-4432-8634-6c41e4cde734",
"score_obtained": 1,
"value": "Yes"
},
{"comment": "",
"fail": false,
"id": "f23b5e63-b24c-49f7-aa46-eb7499cdf89d",
"score_obtained": 1,
"value": "Yes"
},
{"comment": "",
"fail": false,
"id": "4798443d-eaf3-46e7-bc9f-1f03ccee871a",
"score_obtained": 1,
"value": "Yes"
}],
"score_obtained": 3
},
{"id": "f5a83974-3be3-4f69-a9de-49866213b383",
"questions": [ {
"comment": "",
"fail": false,
"id": "52ec152b-fce8-464d-a8cf-b4ae82bfb5d9",
"score_obtained": 0,
"value": "N/A"
},
{"comment": "",
"fail": false,
"id": "627ce8fd-2d29-44d9-8c3d-49dfdab9f7b2",
"score_obtained": 0,
"value": "N/A"
},
{ "comment": "",
"fail": false,
"id": "a6efd5fe-42e1-4411-b197-ee715b579281",
"score_obtained": 0,
"value": "N/A"
},
{"comment": "",
"fail":false,
"id": "aea7d958-c27e-44ab-a32f-c2388b8c6aab",
"score_obtained": 1,
"value": "Yes"
},
{"comment": "",
"fail": false,
"id": "860ac0b2-c325-443d-8f91-63879d09bac8",
"score_obtained": 0,
"value": "N/A"
} ],
"score_obtained": 1
},
{"id": "6a5fa573-8dc5-4dbb-b6cd-2e01445c3b4c",
"questions": [
{"comment": "",
"fail": false,
"id": "22e2cc11-c886-4b56-8de6-e97b773de4d0",
"score_obtained": 1,
"value": "Yes"
},
{"comment": "Agent transferred call incorrectly. Another agent advised her of it then call disconnected. ",
"fail":true,
"id": "39b2ab0d-7372-408e-b8e2-886be10239de",
"score_obtained": 0,
"value": "No"}
],
"score_obtained": 1
},
{"id": "d1deed99-e8aa-49f1-8c32-079887fd6838",
"questions": [
{"comment": "",
"fail": false,
"id": "b951c53c-52b9-4a08-b3c6-70298643db22",
"score_obtained": 1,
"value": "Yes"
},
{"comment": "",
"fail": false,
"id": "2321f675-01f9-4975-b7e9-d57feb865d0e",
"score_obtained": 1,
"value": "Yes"
},
{"comment": "",
"fail": false,
"id": "6b0eb24c-f31c-41f0-85d3-56805d42284d",
"score_obtained": 1,
"value": "Yes"
},
{"comment": "",
"fail":false,
"id": "7e5e7a2e-60c0-4416-814e-fe19c9ab2361",
"score_obtained": 1,
"value": "Yes"
},
{
"comment": "",
"fail": false,
"id": "19f6ec0a-4c4c-49b6-962e-d029a0326d27",
"score_obtained": 1,
"value": "No"
} ],
"score_obtained": 5
},
{"id": "6c41a906-3d69-469d-9391-c814a6124ec1",
"questions": [
{"comment": "",
"fail": false,
"id": "d72fca9d-323d-4238-980e-c0aec746e1fc",
"score_obtained": 1,
"value": "Yes"},
{
"comment": "",
"fail": false,
"id": "d1af8d8e-6a97-4111-bad7-a64695f2c3f7",
"score_obtained": 1,
"value": "Yes"
},
{
"comment": "",
"fail":true,
"id": "c1251cb6-c3fe-4f69-bbe5-9510f150d18a",
"score_obtained": 0,
"value": "No"
}],
"score_obtained": 2
},
{
"id": "ca1c275b-1cd0-49c9-a4d7-9fd0544b4bbf",
"questions": [
{
"comment": "",
"fail": true,
"id": "4f3268ba-4e8d-46b8-a50a-69ea9de88a6a",
"score_obtained": 0,
"value": "No"
},
{
"comment": "",
"fail": true,
"id": "cb82d886-8e2c-4d4c-a8f8-b5c769bf289a",
"score_obtained": 0,
"value": "No"
},
{
"comment": "",
"fail": true,
"id": "ea9aa819-6905-4f15-a702-3713bbb033a9",
"score_obtained": 0,
"value": "No"
}
],
"score_obtained": 0
},
{
"id": "5743b6e8-ac6f-4d34-8561-f7e5191d5f37",
"questions": [
{
"comment": "",
"fail": false,
"id": "af04685e-5c73-47be-8282-493960cce3e0",
"score_obtained": 1,
"value": "Yes"
},
{
"comment": "",
"fail": false,
"id": "67b8ea9f-d481-42c2-9343-e586875e0929",
"score_obtained": 1,
"value": "Yes"
},
{
"comment": "",
"fail":false,
"id": "9fc25686-a63c-4db4-b2aa-dcf8666d2147",
"score_obtained": 1,
"value": "Yes"
},
{
"comment": "",
"fail": false,
"id": "410616c0-0d41-4322-b6a3-df11c3c28963",
"score_obtained": 1,
"value": "Yes"
},
{
"comment": "",
"fail": false,
"id": "575c978e-365d-4b83-842e-acfe41de09ae",
"score_obtained": 1,
"value": "Yes"
} ],
"score_obtained": 5
},
"id": "bced1392-24b2-404f-91be-9df6d68e0c8d",
"questions": [
{
"comment": "",
"fail": false,
"id": "e2250777-8bba-4fee-b9b4-1535b42be14c",
"score_obtained": 0,
"value": "No"
},
{
"comment": "",
"fail": false,
"id": "533281a0-63db-4af6-b41e-7b967a456332",
"score_obtained": 0,
"value": "No"
},
{
"comment": "",
"fail": false,
"id": "c9cf8f64-427b-4927-8ffb-02454e6daa43",
"score_obtained": 0,
"value": "No"
},
{
"comment": "",
"fail": false,
"id": "7c4df8ba-0d89-4703-b4fe-3e6f88c3fa76",
"score_obtained": 0,
"value": "No"
},
"comment": "",
"fail": false,
"id": "0bf1e679-a300-475e-9fb8-613317d42570",
"score_obtained": 0,
"value": "No"
},
{
"comment": "Advise agent get the link with forms update
dates to provide clients. No transfer needed to be completed. ",
" fail": false,
"id": "52ba5be6-7def-469a-a31f-7c74c86730ac",
"score_obtained": 0,
"value": ""
}
],
"score_obtained": 0
}
]},
"scores_obtained": {
"auto_fail": false,
"final_score": 17,
"grade_assigned": "Pass",
"percent_score": 77.27,
"total_bonus": 0,
"total_penalties": 0,
"total_points": 22
}
}
]
}
]}]}}
Thanks,
You can use FLATTEN function to parse nested arrays in JSON.
refer to
https://docs.snowflake.com/en/user-guide/querying-semistructured#using-the-flatten-function-to-parse-nested-arrays
To simplify, I have taken a small part of your JSON data and tested it.
CREATE OR REPLACE TABLE xyz
(
src variant
)
AS
SELECT PARSE_JSON(column1) AS src
FROM VALUES
('{"value":
{"evaluation_forms":
[ {"evaluations":
[ {"channel_meta":
{"after_call_work_time": [],
"agent_first_name": ["KATRINA"],
"agent_hung_up": [],
"agent_last_name": ["COX"]
}
} ]
} ]
}
} '
) v;
SELECT
src:value AS valuest,
src:value:evaluation_forms as evaluation_forms,
v.value:evaluations as evaluations,
ve.value:channel_meta as channel_meta,
Fn.value as agent_first_name
FROM
xyz
, LATERAL FLATTEN(INPUT => SRC:value:evaluation_forms) v
, LATERAL FLATTEN(INPUT => v.value:evaluations) ve
, LATERAL FLATTEN(INPUT => ve.value:channel_meta:agent_first_name) fn
;

json jq request format

I need help to extract data from this JSON file using jq.
The app flv then verify the streamname mystrame is active and extract meta.video.height
I did try lot of queries without success and my jq knowledge is poor.
{
"port": 1935,
"server_index": 0,
"applications": [{
"name": "hls",
"live": {
"streams": [{
"name": "donbosco",
"time": 2380739,
"bw_in": 2112440,
"bytes_in": 541618713,
"bw_out": 0,
"bytes_out": 0,
"bw_audio": 35544,
"bw_video": 2076888,
"clients": [{
"id": 453,
"address": "127.0.0.1",
"time": 2380959,
"flashver": "FMLE/3.0 (compatible; Lavf57.83.100)",
"dropped": 0,
"avsync": 28,
"timestamp": 2382635,
"publishing": true,
"active": true
}],
"records": [],
"meta": {
"video": {
"width": 1168,
"height": 720,
"frame_rate": 25,
"codec": "H264",
"profile": "High",
"level": 3.1
},
"audio": {
"codec": "AAC",
"profile": "LC",
"channels": 2,
"sample_rate": 16000
}
},
"nclients": 1,
"publishing": true,
"active": true
}],
"nclients": 1
},
"recorders": {
"count": 0,
"lists": []
}
},
{
"name": "flv",
"live": {
"streams": [{
"name": "mystream",
"time": 2382811,
"bw_in": 2059096,
"bytes_in": 541841549,
"bw_out": 2059096,
"bytes_out": 543351459,
"bw_audio": 35472,
"bw_video": 2023624,
"clients": [{
"id": 452,
"address": "127.0.0.1",
"time": 2382727,
"flashver": "LNX 9,0,124,2",
"dropped": 0,
"avsync": -12,
"timestamp": 2384520,
"publishing": false,
"active": true
},
{
"id": 451,
"address": "127.0.0.1",
"time": 2383031,
"flashver": "FMLE/3.0 (compatible; Lavf58.74.100)",
"dropped": 0,
"avsync": -12,
"timestamp": 2384520,
"publishing": true,
"active": true
}
],
"records": [],
"meta": {
"video": {
"width": 1168,
"height": 720,
"frame_rate": 25,
"codec": "H264",
"profile": "High",
"level": 3.1
},
"audio": {
"codec": "AAC",
"profile": "LC",
"channels": 2,
"sample_rate": 16000
}
},
"nclients": 2,
"publishing": true,
"active": true
}],
"nclients": 2
},
"recorders": {
"count": 0,
"lists": []
}
}
]
}
Are you asking for help with the command-line JSON processor jq or the JavaScript library jQuery? They are not the same. For jq, try
jq '
.applications
| map(select(.name == "flv"))[].live.streams
| map(select(.name == "mystream" and .active))[].meta.video.height
'
720
Demo

Parsing parent and child element into a csv using jq

I have a big file that has lines as below.
{
"total": 320,
"assets": [
{
"audit": {
"created": {
"date": "2019-09-30T12:38:01.421Z"
},
"updated": {}
},
"organizationId": "12345678",
"id": 211123898,
"name": "groupId:760c47ad-c9f2958be:assetId:8o-api",
"exchangeAssetName": "8O API",
"groupId": "760c47ad-c9f2958be",
"assetId": "8o-api",
"apis": [
{
"audit": {
"created": {
"date": "2019-09-30T12:38:03.139Z"
},
"updated": {
"date": "2020-03-09T21:37:55.745Z"
}
},
"organizationId": "12345678",
"id": 15822364,
"groupId": "760c47ad-c9f2958be",
"assetId": "8o-api",
"assetVersion": "1.0.0",
"productVersion": "v1",
"description": null,
"tags": [],
"order": 1,
"providerId": null,
"deprecated": false,
"lastActiveDate": "2021-01-15T22:43:33.881Z",
"isPublic": false,
"stage": "release",
"lastActiveDelta": 7,
"pinned": false,
"activeContractsCount": 6,
"autodiscoveryInstanceName": "v1:15822364"
}
],
"totalApis": 1,
"autodiscoveryApiName": "groupId:760c47ad-c9f2958be:assetId:8o-api"
},
{
"audit": {
"created": {
"date": "2018-06-22T19:41:35.760Z"
},
"updated": {
"date": "2018-09-13T06:20:51.151Z"
}
},
"organizationId": "760c47ad-c9f2958be",
"id": 210914379,
"name": "hips-ts",
"exchangeAssetName": "hips-ts",
"groupId": "760c47ad-c9f2958be",
"assetId": "hips-ts",
"apis": [
{
"audit": {
"created": {
"date": "2018-06-22T19:41:35.759Z"
},
"updated": {
"date": "2020-03-09T21:37:55.745Z"
}
},
"organizationId": "760c47ad-c9f2958be",
"id": 15470738,
"groupId": "760c47ad-c9f2958be",
"assetId": "hips-ts",
"assetVersion": "1.0.0",
"productVersion": "v1",
"description": null,
"tags": [],
"order": 1,
"providerId": null,
"deprecated": false,
"lastActiveDate": "2021-01-15T22:43:30.004Z",
"endpointUri": null,
"isPublic": false,
"stage": "release",
"lastActiveDelta": 11,
"pinned": false,
"activeContractsCount": 1,
"autodiscoveryInstanceName": "1-test"
}
],
"totalApis": 1,
"autodiscoveryApiName": "hips-ts"
}
]
}
I am trying to use jq to just get the assetId and the activeContractsCount from this in a comma separated way.
So my output for this text should be
8o-api, 6
hips-ts, 1
I tried the following wiht jq jq -r '[.assets[].assetId, .assets[].apis[].activeContractsCount]|#csv' and I tried mapping too but nothing seems to stick.
Can you help me here? Any help is appreciated.
The following will produce exactly two columns, one for the "assetID" and one for the count:
.assets[].apis[]
| [.assetId, .activeContractsCount]
| #csv
I figured it out as soon as I posted the question. But please let me know if there's a better way to do this.
jq -r '.assets[]|[.apis[].assetId, .apis[].activeContractsCount]|#csv'

How to get a json key that contains a specific string with jq?

I have a json data like this:
{
"success": true,
"module": {
"endpoint": {
"mode": "pc",
"protocolVersion": "2.0"
},
"reload": true,
"data": {
"leftContainer_CL": {
"id": "CL",
"tag": "leftContainer",
"fields": {
"css": {
"floatPosition": "left",
"width": "788px"
},
"tag": "leftContainer"
},
"type": "container"
},
"container_C": {
"id": "C",
"tag": "container",
"fields": {
"css": {
"marginTop": "12px"
},
"tag": "container"
},
"type": "container"
},
"delivery_dfdaf8a8a": {
"id": "dfdaf8a8a",
"tag": "delivery",
"fields": {
"selectPos": "right",
"deliveryBy": {
"text": "Disediakan oleh",
"poster": "ALL ITEM STORE"
},
"options": [
{
"highlight": false,
"deliveryId": "STANDARD",
"bgColor": "#fafafa",
"price": "Rp18.900",
"disable": false,
"reachTime": "Dapatkan pada\n 3-4 Apr 2018",
"liveUp": false,
"selected": true
}
],
"style": "bar"
},
"type": "biz"
},
"rightContainer_CR": {
"id": "CR",
"tag": "rightContainer",
"fields": {
"css": {
"floatPosition": "right",
"width": "388px"
},
"tag": "rightContainer"
},
"type": "container"
},
"delivery_d43597338a": {
"id": "d43597338a",
"tag": "delivery",
"fields": {
"selectPos": "right",
"deliveryBy": {
"text": "Disediakan oleh",
"poster": "incredible accessories hp"
},
"options": [
{
"highlight": false,
"deliveryId": "STANDARD",
"bgColor": "#fafafa",
"price": "Rp37.800",
"disable": false,
"reachTime": "Dapatkan pada\n 3-4 Apr 2018",
"liveUp": false,
"selected": true
}
],
"style": "bar"
},
"type": "biz"
},
"orderSummary_6": {
"id": "6",
"tag": "orderSummary",
"fields": {
"isOpen": "false",
"summarys": [
{
"tail": "(3 barang)",
"title": "Subtotal",
"value": "Rp23.557"
},
{
"title": "Biaya pengiriman",
"value": "Rp56.700"
}
],
"title": "Ringkasan Pesanan\r\n"
},
"type": "biz"
},
"root_0": {
"id": "0",
"tag": "root",
"fields": {
"count": 3,
"title": "Troli belanja Saya"
},
"type": "root"
},
"item_i77997d6b": {
"id": "i77997d6b",
"tag": "item",
"fields": {
"img": "https://id-live.slatic.net/original/08c1396908dc240625751b09decb4211.jpg",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "ALL ITEM STORE",
"title": "Case Slim Black Matte Xiaomi Redmi 4A Softcase Black",
"stockTip": {},
"valid": true,
"itemId": "143800088",
"operations": [
"wishlist",
"delete"
],
"sellerId": "100124080",
"price": {
"price": 6000,
"currentPrice": "Rp6.000",
"originPrice": "Rp30.000",
"promotionRatio": "-80%"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Softcase, Hitam",
"productVariant": "SO908ELAAVYY4AANID-72544754",
"brandId": "17818",
"skuId": "157608391"
},
"itemUrl": "https://www.lazada.co.id/products/i143800088-s157608391.html?urlFlag=true&mp=1",
"cartItemId": 2006547819
},
"type": "biz"
},
"location_2": {
"id": "2",
"tag": "location",
"fields": {
"buttonText": "GANTI\r\n",
"editable": true,
"postCode": "",
"style": "casAddress",
"label": "Lokasi",
"title": "Jawa Tengah,Kab. Boyolali,Ampel",
"addressId": "R2388357-R80010396-R80015219"
},
"type": "biz"
},
"voucherInput_7": {
"id": "7",
"tag": "voucherInput",
"fields": {
"buttonText": "GUNAKAN",
"placeHolder": "Masukkan Kode Voucher",
"status": "default"
},
"type": "biz",
"validate": {
"value": [
{
"msg": "Maaf, voucher ini tidak dapat digunakan. Silahkan periksa jika ada kesalahan penulisan",
"regex": "^$|^[ ]{0,5}[A-Za-z0-9~!##%&*()_+?<>{}|-]{1,100}[ ]{0,5}$"
}
]
}
},
"shop_43597338a_s2c": {
"id": "43597338a_s2c",
"tag": "shop",
"fields": {
"badges": [],
"link": "//www.lazada.co.id/shop/incredible-accessories-hp",
"name": "incredible accessories hp"
},
"type": "biz"
},
"item_i7799f86e": {
"id": "i7799f86e",
"tag": "item",
"fields": {
"img": "http://id-live-02.slatic.net/p/2/case-anti-shock-anti-crack-elegant-softcase-for-xiaomi-redmi-5a-white-clear-free-tempered-glass-1273-94487227-9f8ddff53bde3f8de9eb514ba2172361-catalog.jpg",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "incredible accessories hp",
"title": "Case Anti Shock / Anti Crack Elegant Softcase for Xiaomi Redmi 5A - White Clear + Free Tempered Glass",
"stockTip": {},
"valid": true,
"itemId": "160714927",
"operations": [
"wishlist",
"delete"
],
"sellerId": "53631",
"price": {
"price": 13580,
"currentPrice": "Rp13.580",
"originPrice": "Rp25.000",
"promotionRatio": "-46%"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Softcase, Bening",
"productVariant": "SO908ELAB716EPANID-97510528",
"brandId": "17818",
"skuId": "183461134"
},
"itemUrl": "https://www.lazada.co.id/products/i160714927-s183461134.html?urlFlag=true&mp=1",
"cartItemId": 2006579310
},
"type": "biz"
},
"package_p43597338a": {
"id": "p43597338a",
"tag": "package",
"fields": {},
"type": "biz"
},
"listHeader_H": {
"id": "H",
"tag": "listHeader",
"fields": {
"middle": "HARGA",
"left": "3 barang",
"right": "KUANTITAS"
},
"type": "biz"
},
"delivery_3": {
"id": "3",
"tag": "delivery",
"fields": {
"selectPos": "left",
"options": [
{
"highlight": false,
"deliveryId": "STANDARD",
"bgColor": "#fafafa",
"price": "Rp56.700",
"disable": false,
"icon": "https://laz-img-cdn.alicdn.com/tfs/TB1UpyCpfDH8KJjy1XcXXcpdXXa-72-72.png",
"name": "Standar",
"reachTime": "Dapatkan pada\n 3-4 Apr 2018",
"liveUp": false,
"selected": true
}
],
"style": "card",
"title": "Pengiriman yang dipilih"
},
"type": "biz"
},
"orderTotal_8": {
"id": "8",
"tag": "orderTotal",
"fields": {
"button": {
"enable": true,
"text": "LANJUTKAN KE PEMBAYARAN",
"clicked": false
},
"payment": {
"taxTip": "Termasuk PPN, jika berlaku",
"pay": "Rp80.257",
"title": "Total"
}
},
"type": "biz"
},
"shop_fdaf8a8a_s23f9": {
"id": "fdaf8a8a_s23f9",
"tag": "shop",
"fields": {
"badges": [],
"link": "//www.lazada.co.id/shop/all-item-store",
"name": "ALL ITEM STORE"
},
"type": "biz"
},
"floatTips_4": {
"id": "4",
"tag": "floatTips",
"fields": {
"tips": []
},
"type": "biz"
},
"item_i7790e0f9": {
"id": "i7790e0f9",
"tag": "item",
"fields": {
"img": "http://id-live-02.slatic.net/p/2/case-anti-shock-anti-crack-elegant-softcase-for-xiaomi-redmi-note4x-white-clear-8431-85175402-0bec01e88741744ae5461c4b3a4ae160-catalog.jpg",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "incredible accessories hp",
"title": "Case Anti Shock / Anti Crack Elegant Softcase for Xiaomi Redmi Note 4x - White Clear",
"stockTip": {},
"valid": true,
"itemId": "108849535",
"operations": [
"wishlist",
"delete"
],
"sellerId": "53631",
"price": {
"price": 3977,
"currentPrice": "Rp3.977",
"originPrice": "Rp15.000",
"promotionRatio": "-73%"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Sarung, Bening",
"productVariant": "CA529ELAAC6GUEANID-27304198",
"brandId": "10464",
"skuId": "110628148"
},
"itemUrl": "https://www.lazada.co.id/products/i108849535-s110628148.html?urlFlag=true&mp=1",
"cartItemId": 2005983481
},
"type": "biz"
},
"package_pfdaf8a8a": {
"id": "pfdaf8a8a",
"tag": "package",
"fields": {},
"type": "biz"
}
},
"hierarchy": {
"component": [
"container",
"delivery",
"item",
"shop",
"package",
"listHeader",
"orderSummary",
"leftContainer",
"orderTotal",
"floatTips",
"root",
"location",
"rightContainer",
"voucherInput"
],
"root": "root_0",
"structure": {
"package_p43597338a": [
"delivery_d43597338a",
"shop_43597338a_s2c",
"item_i7799f86e",
"item_i7790e0f9"
],
"leftContainer_CL": [
"delivery_3",
"listHeader_H",
"package_pfdaf8a8a",
"package_p43597338a"
],
"container_C": [
"leftContainer_CL",
"rightContainer_CR"
],
"rightContainer_CR": [
"location_2",
"orderSummary_6"
],
"orderSummary_6": [
"voucherInput_7",
"orderTotal_8"
],
"root_0": [
"container_C",
"floatTips_4"
],
"package_pfdaf8a8a": [
"delivery_dfdaf8a8a",
"shop_fdaf8a8a_s23f9",
"item_i77997d6b"
]
}
},
"linkage": {
"input": [],
"request": [
"voucherInput_7",
"item_i7799f86e",
"delivery_3",
"orderTotal_8",
"item_i7790e0f9",
"location_2",
"item_i77997d6b"
],
"common": {
"compress": true,
"queryParams": "^^$$1afe141216814f45e9fc6dba84d4863d{$_$}H4sIAAAAAAAAAFWU247bRgyGXyXQ9caYGXJOe5fkJmmLot3de4Ez5OwKlSVBklMkQd69lJsNHBgwZIHfz9NPf+t2Wc/DRGN3/61bRtrbvJ67+26p3V230LPoc6V1777fdROd5XGh+vpu05DLJuu7bRuep0OgjrRtf2rYETGfTyN9JabTNfh0nlnG02Xc13k6LbTSeTv9fZH1y1/XZxVbZWJZ3w9ff7xRxXGutA/z9DTs46H6G/1Lb55keqaXu9+pnN68n7/MI43D3bvzIqOKEPMq2/aJNfrBQUrg49uHZIw1kMP/T97ZfPQ3b/sHrUoju+/aoJa8zJNM+/aoDdF+WeXa1TztNEyy9h800jUoDoPFWnMIVHwCMMiWCJ2zgVRX+xw+a2M9aHyMsbpqwcUChTgxeMZqbWzkJXl7G88IPkeARApKMCYQeJNYojCEVPTboMcCmOIvibgxtURXLrRaKGKrWdhHMslkE1ss2TjnCA+ujTPtT8Oy9XgkilVQsgEX2AXJgQ3UZCNb1yKEY1LDLud+iDEbMS0rYwAzx+KbE6JmcgCbs02YJShhyi2TI4eiTAHr0ROiZS0mOteYW9JChZwR+CVPbikce2Ev4HJiJmuab6TJIApIkZo4JFZmlKZb/LmiP66jqzVlEhe5GJEUs/XNk6csxYacDmrY9o9C6rf+oxJAHqAkJMc69RbZu+yBQKxFqTEcxA8r9u5wgagLRISDNuECYjAFk3NYUnU+Htczryr+eDmfSRcUlNEukSyVmqLXeNG9NnWF16RBV95emad5p7FPx5QNGnSUpHDUllsyGINQUKSp78L1Rus/eqb9cmsdgGp1vmpLcKjD1JsNTUGdqmu6olvuxjmlpaa7KV6wtkqU1UimOXA6gIjXk1mH55fbaT8olhJJMhFrrlwxRwuAmK00ELD6+8Dmee9Ndz9dxvGu217mpf9Zb7+5qirZ1YoYOXJlWw1r1Zz1w7kAxKvKlXutVzG4WlFvGUyKxkhB9RNL9ibmmoGTnkJFBT/Pl/oi66dpuex9VMa65LRQ0fRWnDjSZDogFZJkkYL+HfwHDyba3BsFAAA=",
"submitParams": "^^$$f7898231e0216a924bcaa64d213a61ba{$_$}H4sIAAAAAAAAADXMQQrDMAwEwL/oHPSA3PqBUsgLto4bDJJtJPvS4L/XCfS2uwx7UoumKUNoPakK2qeY0ko10EIVR5w5wBqNhTI0bhXhv/kk3aM93NORr4MgcH9OdomiLPhiB9+YtexRuEuzkrnCoM5bf2tqr7vQGD8eVpdVjwAAAA=="
},
"signature": "89dffd9ca23307e603556a4c896e4c56"
}
}
}
With jq I can do this:
[me#linux]$ cat /tmp/json | jq '.module | .data | keys'
[
"container_C",
"delivery_3",
"delivery_d43597338a",
"delivery_dfdaf8a8a",
"floatTips_4",
"item_i7790e0f9",
"item_i77997d6b",
"item_i7799f86e",
"leftContainer_CL",
"listHeader_H",
"location_2",
"orderSummary_6",
"orderTotal_8",
"package_p43597338a",
"package_pfdaf8a8a",
"rightContainer_CR",
"root_0",
"shop_43597338a_s2c",
"shop_fdaf8a8a_s23f9",
"voucherInput_7"
]
I need to get orderTotal_8 but please note that the number 8 is always changing, so it can be orderTotal_10 or orderTotal_3 etc... How can I get this key with pure jq command if possible, without the help of grep / awk ? So the result should be like this orderTotal_8
If you want to form a subarray of items satisfying some condition, just add map(select( CONDITION )) to the pipeline, e.g.
.module | .data | keys | map(select(test("^orderTotal_")))
If you just want a stream of the items matching the condition, then you could first form the stream, and then make the selection:
.module | .data | keys[] | select(test("^orderTotal_"))
For efficiency and other reasons, you might want to consider using keys_unsorted instead of keys.

Getting the album link from a list of albums with Facebook Graph

The json below is the response I get from the server for requesting /id/albums, but I want to use that data to get the link to the album that has all the pictures in json format. The "link" field provided is to the actual desktop site, but I need the json. How would I use the json data provided (below) to send a request to graph.facebook.com to get the pictures within the corresponding album in json format?
{
"data": [
{
"id": "150228731810007",
"from": {
"name": "James McMahon",
"id": "100004686423103"
},
"name": "Profile Pictures",
"link": "https://www.facebook.com/album.php?fbid=150228731810007&id=100004686423103&aid=1073741831",
"cover_photo": "150228735143340",
"count": 2,
"type": "profile",
"created_time": "2013-03-15T05:29:24+0000",
"updated_time": "2013-11-09T17:12:36+0000",
"can_upload": false
},
{
"id": "233767233456156",
"from": {
"name": "James McMahon",
"id": "100004686423103"
},
"name": "Mobile Uploads",
"link": "https://www.facebook.com/album.php?fbid=233767233456156&id=100004686423103&aid=1073741838",
"type": "mobile",
"created_time": "2013-11-09T17:12:30+0000",
"updated_time": "2013-11-09T17:12:30+0000",
"can_upload": false
},
{
"id": "206255352874011",
"from": {
"name": "James McMahon",
"id": "100004686423103"
},
"name": "Aug. 17th, 2013",
"description": "Day with some of the Family",
"link": "https://www.facebook.com/album.php?fbid=206255352874011&id=100004686423103&aid=1073741837",
"cover_photo": "206255402874006",
"count": 8,
"type": "normal",
"created_time": "2013-08-17T21:24:12+0000",
"updated_time": "2013-08-17T21:24:36+0000",
"can_upload": false,
"likes": {
"data": [
{
"id": "1774907390",
"name": "Ashley Carter"
},
{
"id": "646440613",
"name": "Mitzy Lanthier"
},
{
"id": "1801948293",
"name": "Calvin Carter"
},
{
"id": "100000653918655",
"name": "Kimberly Lane Lirette"
}
],
"paging": {
"cursors": {
"after": "MTAwMDAwNjUzOTE4NjU1",
"before": "MTc3NDkwNzM5MA=="
}
}
}
},
{
"id": "150230918476455",
"from": {
"name": "James McMahon",
"id": "100004686423103"
},
"name": "Cover Photos",
"link": "https://www.facebook.com/album.php?fbid=150230918476455&id=100004686423103&aid=1073741833",
"cover_photo": "202581716574708",
"count": 4,
"type": "cover",
"created_time": "2013-03-15T05:43:31+0000",
"updated_time": "2013-08-08T17:26:35+0000",
"can_upload": false
},
{
"id": "158017154364498",
"from": {
"name": "James McMahon",
"id": "100004686423103"
},
"name": "Timeline Photos",
"link": "https://www.facebook.com/album.php?fbid=158017154364498&id=100004686423103&aid=1073741834",
"cover_photo": "179650435534503",
"count": 10,
"type": "wall",
"created_time": "2013-04-07T14:04:04+0000",
"updated_time": "2013-06-12T23:28:45+0000",
"can_upload": false
},
{
"id": "178309025668644",
"from": {
"name": "James McMahon",
"id": "100004686423103"
},
"name": "U.S.Navy D.E.P.",
"description": "Was a pretty fun day. We were out there helping restore this World War 2 Destroyer.",
"link": "https://www.facebook.com/album.php?fbid=178309025668644&id=100004686423103&aid=1073741835",
"cover_photo": "178309055668641",
"count": 4,
"type": "normal",
"created_time": "2013-06-10T00:32:45+0000",
"updated_time": "2013-06-10T00:33:49+0000",
"can_upload": false,
"likes": {
"data": [
{
"id": "100000651398529",
"name": "Jennifer Manuel Hyatt"
},
{
"id": "1801948293",
"name": "Calvin Carter"
},
{
"id": "1522740127",
"name": "Bliss Reane Kinder"
}
],
"paging": {
"cursors": {
"after": "MTUyMjc0MDEyNw==",
"before": "MTAwMDAwNjUxMzk4NTI5"
}
}
}
},
{
"id": "150228468476700",
"from": {
"name": "James McMahon",
"id": "100004686423103"
},
"name": "Untitled Album",
"description": "03112013",
"link": "https://www.facebook.com/album.php?fbid=150228468476700&id=100004686423103&aid=1073741830",
"cover_photo": "150228475143366",
"count": 1,
"type": "normal",
"created_time": "2013-03-15T05:27:54+0000",
"updated_time": "2013-03-15T05:28:17+0000",
"can_upload": false
}
],
"paging": {
"cursors": {
"after": "MTUwMjI4NDY4NDc2NzAw",
"before": "MTUwMjI4NzMxODEwMDA3"
}
}
}
Response received in 237 ms
You have the id field- that's the album-id
So, you can create the link by yourself, just like this-
https://graph.facebook.com/<ALBUM-ID>/photos
from this you can fetch all the photos of a particular album (but remember that you'll need the access token- of-course)
https://graph.facebook.com/<ALBUM-ID>/photos?access_token=<ACCESS-TOKEN>