Related
I have a lot of data I need to parse though.
I need to pull all pid's and price's.
`
[
{
"id": 159817,
"price": "10.69",
"stocked": true,
"store": {
"id": 809,
"nsn": "22036-0",
"pricingSource": "manual",
"lastUpdated": "2022-12-05T15:24:33.908Z"
},
"sharedFields": {
"type": "PRODUCT",
"id": 24549,
"pid": "12079",
"labels": [
{
"type": "default",
"value": "Chicken Sandwich",
"locale": "en"
},
{
"type": "fresh",
"value": "Chicken",
"locale": "en"
},
{
"type": "product_json",
"value": "Chicken",
"locale": "en"
}
],
"calMin": 600,
"calMax": 600,
"lastUpdated": "2021-12-31T13:49:22.794Z"
}
},
{
"id": 159818,
"price": "9.29",
"stocked": true,
"store": {
"id": 809,
"nsn": "22036-0",
"pricingSource": "manual",
"lastUpdated": "2022-12-05T15:24:33.908Z"
},
"sharedFields": {
"type": "PRODUCT",
"id": 25,
"pid": "1",
"labels": [
{
"type": "default",
"value": "Ham Sandwich",
"locale": "en"
},
{
"type": "fresh",
"value": "Ham",
"locale": "en"
}
],
"calMin": 540,
"calMax": 540,
"lastUpdated": "2021-07-09T19:30:00.326Z"
}
}
]
`
and I need to place them into a string like this, but on a scale of 150 products. I'd also need to change "pid" to "productId"
[{ "productId": "46238", "price": 6.09 }, { "productId": "40240", "price": 1.49 }]
I need to add a string before this data, but I'm pretty confident I can figure that part out.
I am pretty open to the easiest suggestion, whether that be VBS, Excel macro, etc.
I've the below json data.
{
"images": [
{
"id": "79334504-3e48-4411-b602-afe920e32e14",
"name": "rhel-7-factory-os-ready",
"updated": "2019-05-07T15:51:00Z"
},
{
"id": "05569058-0b47-4c05-8ce7-f09b2e32076a",
"name": "sles-12-factory-os-ready",
"updated": "2019-05-07T15:48:59Z"
},
{
"id": "77c131bc-4dd6-4290-9dfb-89ddebc609f4",
"name": "sles-11-factory-os-ready",
"updated": "2019-05-07T15:45:10Z"
},
{
"id": "d42b7a07-e329-46ac-82c1-28875498b145",
"name": "rhel-6-factory-os-ready",
"updated": "2019-05-07T15:44:54Z"
},
{
"id": "d282ae55-ecc6-47a3-bb2f-4354bebf33e1",
"name": "rhel-7-factory-base-vg00",
"updated": "2019-05-07T15:37:25Z"
},
{
"id": "0c0fb244-7553-4f20-bf3b-8e32d0527292",
"name": "sles-12-factory-base-vg00",
"updated": "2019-05-07T15:32:14Z"
},
{
"id": "14a34117-91d5-4cbf-b039-613fd8b5ea65",
"name": "rhel-6-factory-base-vg00",
"updated": "2019-05-07T15:29:28Z"
},
{
"id": "bf465c2d-9f4c-44a9-9cc8-ff488b79e9f6",
"name": "rhel-7-factory-base",
"updated": "2019-05-07T15:28:00Z"
},
{
"id": "90d4e12d-6d7f-4f59-a4e6-28b1757f95bc",
"name": "sles-11-factory-base-vg00",
"updated": "2019-05-07T15:24:19Z"
},
{
"id": "30109a53-4aab-4fb5-87ff-7650e75731b0",
"name": "rhel-6-factory-base",
"updated": "2019-05-07T15:20:39Z"
},
{
"id": "80cd641b-bb53-46f7-b8f6-7f287507fc3c",
"name": "sles-12-factory-base",
"updated": "2019-05-07T15:20:10Z"
},
{
"id": "dc2deb91-2ff0-4d9e-a44d-fa2d7a8e1c62",
"name": "sles-11-factory-base",
"updated": "2019-05-07T15:18:05Z"
},
{
"id": "b6646eab-5908-4db4-a93a-1ca0ce52b76b",
"name": "sles-11-factory-os-ready",
"updated": "2019-05-07T14:27:41Z"
},
{
"id": "850cdd08-a5a7-4e6b-a906-4fda157257b6",
"name": "sles-12-factory-base",
"updated": "2019-05-07T14:23:40Z"
},
{
"id": "30325ffd-f17a-4db8-a2ef-a2e529163f03",
"name": "sles-11-factory-base-vg00",
"updated": "2019-05-07T14:08:22Z"
},
{
"id": "70f49bc1-f793-4d1d-8317-e2d1d35993f7",
"name": "rhel-6-factory-base-vg00",
"updated": "2019-05-07T13:42:01Z"
},
{
"id": "6bb77f3d-335b-459d-8aa1-dd3effd60672",
"name": "rhel-6-factory-os-ready",
"updated": "2019-05-07T13:40:17Z"
},
{
"id": "1cbfe793-5ca5-4310-b121-e5065ffa0cf8",
"name": "rhel-6-factory-base-vg00",
"updated": "2019-05-07T13:25:46Z"
},
{
"id": "17d0b51f-1c19-472a-9104-31624435bd63",
"name": "rhel-7-factory-os-ready",
"updated": "2019-05-07T13:18:55Z"
},
{
"id": "4e1f6f7a-90fc-4055-9ee7-d284656fcd58",
"name": "rhel-7-factory-base-vg00",
"updated": "2019-05-07T12:41:21Z"
},
{
"id": "7129df12-ae5b-47ff-905d-1e7bf79069cb",
"name": "rhel-7-factory-base",
"updated": "2019-05-07T12:31:32Z"
},
{
"id": "a37ce4d3-fc3e-4ae9-8d24-038c638be629",
"name": "rhel-6-factory-base-vg00",
"updated": "2019-05-07T12:30:08Z"
},
{
"id": "294821b3-e9df-4b12-ae39-8deb8f9c72ff",
"name": "rhel-6-factory-base",
"updated": "2019-05-07T12:21:36Z"
},
{
"id": "520ae1ca-bb2f-4ccb-bed3-886ee39ccd5e",
"name": "sles-11-factory-base",
"updated": "2019-05-07T12:21:00Z"
},
{
"id": "e041c0ed-c30f-4c61-a695-682e5a80026a",
"name": "rhel-6-factory-os-ready",
"updated": "2019-04-29T14:17:52Z"
},
{
"id": "068ae5f0-d7a0-4419-829e-18eb25551c94",
"name": "rhel-6-factory-base",
"updated": "2019-04-29T14:04:20Z"
},
{
"id": "2dfa8476-54dd-4dc5-80cc-5033466f2732",
"name": "rhel-7-factory-base",
"updated": "2019-04-26T13:40:59Z"
},
{
"id": "61a5a77a-0e8a-47d0-938e-6202c5cc5177",
"name": "rhel-7-factory-os-ready",
"updated": "2019-04-26T13:40:11Z"
},
{
"id": "b877f241-caa1-43c4-9465-fb5019d44f9b",
"name": "sles-12-factory-base-vg00",
"updated": "2019-04-26T13:45:40Z"
},
{
"id": "baf4c87d-8363-48cf-ae02-be9caef4f60d",
"name": "sles-12-factory-base",
"updated": "2019-04-26T13:41:31Z"
},
{
"id": "67a2ffa1-6591-42cb-95db-d2b1a854a78d",
"name": "sles-11-factory-os-ready",
"updated": "2019-04-26T10:17:26Z"
}
]
}
I would like to group by above json by the name attribute like below.
{
"rhel-7-factory-os-ready" : [
{
"id": "79334504-3e48-4411-b602-afe920e32e14",
"updated": "2019-05-07T15:51:00Z"
},
{
"id": "17d0b51f-1c19-472a-9104-31624435bd63",
"updated": "2019-05-07T13:18:55Z"
},
{
"id": "61a5a77a-0e8a-47d0-938e-6202c5cc5177",
"updated": "2019-04-26T13:40:11Z"
}
],
"rhel-6-factory-os-ready" : [
{
"id": "d42b7a07-e329-46ac-82c1-28875498b145",
"updated": "2019-05-07T15:44:54Z"
},
{
"id": "6bb77f3d-335b-459d-8aa1-dd3effd60672",
"updated": "2019-05-07T13:40:17Z"
},
{
"id": "e041c0ed-c30f-4c61-a695-682e5a80026a",
"updated": "2019-04-29T14:17:52Z"
}
]
}
I somehow couldn't figure out how I could achieve this with ansible. It would be great if someone could help me with this.
Thanks in advance,
Harsha
It turns out that Ansible has a groupby filter already:
---
- hosts: localhost
gather_facts: false
tasks:
- include_vars:
file: data.json
name: data
- debug:
var: data.images|groupby('name')
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.
I am trying to get json converted from:
{
"Devices": [
{
"Udid": "7a2b0e6c928f2321a75e423ba23ae93d",
"SerialNumber": "RF1D232ZLEE",
"MacAddress": "40F232726FC8",
"Imei": "3576342323280150",
"EasId": "SEC1BC252327E92B",
"AssetNumber": "7a2b0e23223928f2321a75e423ba23ae93d",
"DeviceFriendlyName": "gel1 Android Android 5.0.1 ZLEE ",
"LocationGroupId": {
"Id": {
"Value": 19529
},
"Name": "Group Express"
},
"LocationGroupName": "Group Express",
"UserId": {
"Name": ""
},
"UserName": "",
"UserEmailAddress": "",
"Ownership": "S",
"PlatformId": {
"Id": {
"Value": 5
},
"Name": "Android"
},
"Platform": "Android",
"ModelId": {
"Id": {
"Value": 5
},
"Name": "samsung GT-I9505"
},
"Model": "samsung GT-I9505",
"OperatingSystem": "5.0.1",
"PhoneNumber": "+447881867010",
"LastSeen": "2016-07-06T14:01:03.590",
"EnrollmentStatus": "Unenrolled",
"ComplianceStatus": "NotAvailable",
"CompromisedStatus": false,
"LastEnrolledOn": "2016-06-15T16:01:38.763",
"LastComplianceCheckOn": "0001-01-01T00:00:00.000",
"LastCompromisedCheckOn": "2016-07-06T13:58:26.183",
"IsSupervised": false,
"DeviceMCC": {
"SIMMCC": "234",
"CurrentMCC": "234"
},
"AcLineStatus": 0,
"VirtualMemory": 0,
"Id": {
"Value": 23459
}
},
{
"Udid": "c5f94db71d406dae7f881d3edf059e",
"SerialNumber": "",
"MacAddress": "000C300F9108",
"Imei": "",
"EasId": "D80DB85EC411C8E9B28BC292A603F05C2C0EEEC8",
"AssetNumber": "c592f93db71d406dae7f881d3edf059e",
"DeviceFriendlyName": "user Windows 10 WinRT 10.0.10240 ",
"LocationGroupId": {
"Id": {
"Value": 18498
},
"Name": "Business Solutions"
},
"LocationGroupName": "Business Solutions",
"UserId": {
"Name": ""
},
"UserName": "",
"UserEmailAddress": "",
"Ownership": "C",
"PlatformId": {
"Id": {
"Value": 12
},
"Name": "WinRT"
},
"Platform": "WinRT",
"ModelId": {
"Id": {
"Value": 50
},
"Name": "Windows 10"
},
"Model": "Windows 10",
"OperatingSystem": "10.0.10240",
"PhoneNumber": "",
"LastSeen": "2016-05-03T10:54:07.650",
"EnrollmentStatus": "Unenrolled",
"ComplianceStatus": "NotAvailable",
"CompromisedStatus": false,
"LastEnrolledOn": "2016-01-29T16:41:57.760",
"LastComplianceCheckOn": "0001-01-01T00:00:00.000",
"LastCompromisedCheckOn": "0001-01-01T00:00:00.000",
"IsSupervised": false,
"DeviceMCC": {
"SIMMCC": "",
"CurrentMCC": ""
},
"AcLineStatus": 0,
"VirtualMemory": 0,
"Id": {
"Value": 23545
}
}
],
"Page": 0,
"PageSize": 500,
"Total": 13}
To something like:
{"name": "Devices",
"children": [
{"name":"Udid", "size":"7f0dsda63274692ea4f0b66fec67a020158"},
{"name":"SerialNumber", "size":"P988KJSPQF938"},
{"name":"MacAddress", "size":"1HJUSUD031C4"},
{"name":"Imei", "size":""},
{"name":"EasId", "size":"ApKJSPQF193"},
{"name":"AssetNumber", "size":"7f0cda636b3305fea4f0b66fec9997267a020158"},
{"name":"DeviceFriendlyName", "size":"TMcKenz iPad iOS 7.1.4 F193 "},
{"name":"LocationGroupId",
"children": [
{"name":"Id","size":7488},
{"name":"Name","size":"MCM"}
]
},
{"name":"UserId",
"children": [
{"name":"Id","size":6418},
{"name":"Name","size":"Tom McKenz"}
]
},
{"name":"UserName", "size":"TMcKenz"},
{"name":"UserEmailAddress", "size":"TMcKenz#awaw.com"}
]
}
Not sure what is the best practice here: is it possible to use D3.nest or do you need to iterate through all the nodes and change to 'name' and 'children' accordingly.
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>