I need some help with my syntax please in trying to get thevalue from a key. Given the following json object:
{
"records": [
{
"id": "recD17v5uIGpA7jYU",
"fields": {
"header h1": "Clouds",
"Email": 1,
"header figure": [
{
"id": "attmeLF6GWqLF3iOS",
"url": "https://dl.airtable.com/.attachments/d6c5f674aeb427dd533cd2c60ab2b29f/f2f99dc0/80__clouds.jpg",
"filename": "80__clouds.jpg",
"size": 2334688,
"type": "image/jpeg",
"thumbnails": {
"small": {
"url": "https://dl.airtable.com/.attachmentThumbnails/7c3dc033b1a7f77fcdeddb2f594a1feb/9a93ab8d",
"width": 36,
"height": 36
},
"large": {
"url": "https://dl.airtable.com/.attachmentThumbnails/6145b560b5c807787814fcf9b39e6130/0f7d0049",
"width": 519,
"height": 512
},
"full": {
"url": "https://dl.airtable.com/.attachmentThumbnails/ecebeb4705ba5531744d556242ddc081/20e10b2a",
"width": 2121,
"height": 2094
}
}
}
]
},
"createdTime": "2019-02-12T09:53:52.000Z"
},
{
"id": "recXiwDKIMSiGd2fn",
"fields": {
"header h1": "People",
"Email": 2,
"header figure": [
{
"id": "attr1iy10UnygtRx0",
"url": "https://dl.airtable.com/.attachments/67484295777d866d6610ef9f84f8bc53/81ae8e6b/A07.jpg",
"filename": "A07.jpg",
"size": 1014718,
"type": "image/jpeg",
"thumbnails": {
"small": {
"url": "https://dl.airtable.com/.attachmentThumbnails/786cc58d3f5b82f4a8414d89b5ea48fb/4a214afc",
"width": 14,
"height": 36
},
"large": {
"url": "https://dl.airtable.com/.attachmentThumbnails/3cb6be2be2b42be2c240f4f2bb9b7901/3bf2b62b",
"width": 512,
"height": 1288
},
"full": {
"url": "https://dl.airtable.com/.attachmentThumbnails/4e56dafdcf39da1f35c1e2f9e96fda6c/07d91945",
"width": 800,
"height": 2013
}
}
}
]
},
"createdTime": "2019-02-12T09:53:52.000Z"
},
{
"id": "recvSJHL3EkSBprs9",
"fields": {
"Email": 3
},
"createdTime": "2019-02-12T09:53:52.000Z"
}
],
"offset": "recvSJHL3EkSBprs9"
}
I'm able to extract the value for "header h1" key with the following jsx
<h2>{record.fields["header h1"]}</h2>
I'm now trying to extract the value from the "url" key. I've tried the following.
<img src={records.fields["header figure"]["url"]} />
and
<img src={records.fields["header figure"][0]["url"]} />
I'm getting TypeError: Cannot read property "url" of undefined.Need some help with my syntax please
List item
your records is an array, also you must specify wich position you want to read:
I tested your json with jq:
jq '.records[0].fields["header figure"][0]["url"]'
delivers
"https://dl.airtable.com/.attachments/d6c5f674aeb427dd533cd2c60ab2b29f/f2f99dc0/80__clouds.jpg"
and
jq '.records[1].fields["header figure"][0]["url"]'
delivers
"https://dl.airtable.com/.attachments/67484295777d866d6610ef9f84f8bc53/81ae8e6b/A07.jpg"
Related
We created a Cloudformation template for auto implementation of the AWS Sitewise monitoring dashboard. We would like to dynamically refer and assign the Asset logical id inside the below dashboard definition.
{\"widgets\":[{\"type\":\"sc-line-chart\",\"title\":\"power_all_plants_5m\",\"x\":0,\"y\":0,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"power_all_plants_5m (All Power Plants)\",\"assetId\":\"0cd25cb9-89f9-4a93-b2bf-88050436f700\",\"propertyId\":\"fd34bba7-4ea2-4d62-9058-ab78b726b61a\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}},{\"type\":\"sc-line-chart\",\"title\":\"Generator-1\",\"x\":3,\"y\":0,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"sum_watts_5m (Generator-1)\",\"assetId\":\"45b97aaa-3f0c-4312-a8a5-a00e4da8ec37\",\"propertyId\":\"e22d9a23-4ac8-432a-816b-cc4a2138b287\",\"dataType\":\"DOUBLE\"},{\"type\":\"iotsitewise\",\"label\":\"rpm (Generator-1)\",\"assetId\":\"45b97aaa-3f0c-4312-a8a5-a00e4da8ec37\",\"propertyId\":\"c6a40902-f07b-40ba-b6c5-3509b069dd4c\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}},{\"type\":\"sc-line-chart\",\"title\":\"Generator-2\",\"x\":0,\"y\":3,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"sum_watts_5m (Generator-2)\",\"assetId\":\"b999319c-20ec-4060-b3b7-bc5ce7ef189c\",\"propertyId\":\"e22d9a23-4ac8-432a-816b-cc4a2138b287\",\"dataType\":\"DOUBLE\"},{\"type\":\"iotsitewise\",\"label\":\"rpm (Generator-2)\",\"assetId\":\"b999319c-20ec-4060-b3b7-bc5ce7ef189c\",\"propertyId\":\"c6a40902-f07b-40ba-b6c5-3509b069dd4c\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}}]}
This JSON literal is converted to YAML by adding backward slashes () along with the double quotes because we are using YAML as the default language of the Cloudformation template otherwise it looks like the below.
{
"widgets": [
{
"type": "sc-line-chart",
"title": "power_all_plants_5m",
"x": 0,
"y": 0,
"height": 3,
"width": 3,
"metrics": [
{
"type": "iotsitewise",
"label": "power_all_plants_5m (All Power Plants)",
"assetId": "0cd25cb9-89f9-4a93-b2bf-88050436f700",
"propertyId": "fd34bba7-4ea2-4d62-9058-ab78b726b61a",
"dataType": "DOUBLE"
}
],
"alarms": [],
"properties": {
"colorDataAcrossThresholds": true
},
"annotations": {
"y": []
}
},
{
"type": "sc-line-chart",
"title": "Generator-1",
"x": 3,
"y": 0,
"height": 3,
"width": 3,
"metrics": [
{
"type": "iotsitewise",
"label": "sum_watts_5m (Generator-1)",
"assetId": "45b97aaa-3f0c-4312-a8a5-a00e4da8ec37",
"propertyId": "e22d9a23-4ac8-432a-816b-cc4a2138b287",
"dataType": "DOUBLE"
},
{
"type": "iotsitewise",
"label": "rpm (Generator-1)",
"assetId": "45b97aaa-3f0c-4312-a8a5-a00e4da8ec37",
"propertyId": "c6a40902-f07b-40ba-b6c5-3509b069dd4c",
"dataType": "DOUBLE"
}
],
"alarms": [],
"properties": {
"colorDataAcrossThresholds": true
},
"annotations": {
"y": []
}
},
{
"type": "sc-line-chart",
"title": "Generator-2",
"x": 0,
"y": 3,
"height": 3,
"width": 3,
"metrics": [
{
"type": "iotsitewise",
"label": "sum_watts_5m (Generator-2)",
"assetId": "b999319c-20ec-4060-b3b7-bc5ce7ef189c",
"propertyId": "e22d9a23-4ac8-432a-816b-cc4a2138b287",
"dataType": "DOUBLE"
},
{
"type": "iotsitewise",
"label": "rpm (Generator-2)",
"assetId": "b999319c-20ec-4060-b3b7-bc5ce7ef189c",
"propertyId": "c6a40902-f07b-40ba-b6c5-3509b069dd4c",
"dataType": "DOUBLE"
}
],
"alarms": [],
"properties": {
"colorDataAcrossThresholds": true
},
"annotations": {
"y": []
}
}
]
}
We would like to assign Asset ID dynamically using "!Ref" with pre-created Asset. We have tried the below variations but no fate.
Existing value -> 0cd25cb9-89f9-4a93-b2bf-88050436f700
Tried below changes:-
[{\"Ref\":\"GeneratorAsset\"}]
!Ref GeneratorAsset
\"!Ref GeneratorAsset\"
{\"Ref\":GeneratorAsset}
{\"Ref\":\"GeneratorAsset\"}
\"{\"Ref\":\"GeneratorAsset\"}\"
\"{\"Fn::Sub\":${GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset} }\"
Here GeneratorAsset is a resource that is already created before Dashboard. Request any Cloudformation expert to help us replace the id value with the correct dynamic string.
Ref link:- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iotsitewise-dashboard.html
Hellow jq experts!
I'm a jq learner and have a json obect composed lists as follows:
{
"image_files": [
{
"id": "img_0001",
"width": 32,
"heigt": 32,
"file_name": "img_0001.png"
},
{
"id": "img_0002",
"width": 128,
"heigt": 32,
"file_name": "img_0002.png"
},
{
"id": "img_0003",
"width": 32,
"heigt": 32,
"file_name": "img_0003.png"
},
{
"id": "img_0004",
"width": 160,
"heigt": 32,
"file_name": "img_0004.png"
}
],
"annotations": [
{
"id": "ann_0001",
"image_id": "img_0001",
"label": "A",
"attributes": {
"type": "letter",
"augmented": false
}
},
{
"id": "ann_0002",
"image_id": "img_0002",
"label": "Good",
"attributes": {
"type": "word",
"augmented": false
}
},
{
"id": "ann_0003",
"image_id": "img_0003",
"label": "C",
"attributes": {
"type": "letter",
"augmented": false
}
},
{
"id": "ann_0004",
"image_id": "img_0004",
"label": "Hello",
"attributes": {
"type": "word",
"augmented": false
}
}
]
}
image_id in the annotations list are foreign key referencing the id in the image_files list.
I want to join image_files and annotations with condition of annotations.attribute.type == "letter".
Expecting following ouptut:
{
"letter_image_files_with_label": [
{
"id": "img_0001",
"width": 32,
"heigt": 32,
"file_name": "img_0001.png",
"label": "A"
},
{
"id": "img_0003",
"width": 32,
"heigt": 32,
"file_name": "img_0003.png",
"label": "C"
}
]
}
How can I produce above result from the json data input?
join explained in jq manual does not seem to use this kind task.
Is there a way for this? Please show me the rope.
Thanks for your generous reading.
Indexing image_files with ids makes this pretty trivial.
INDEX(.image_files[]; .id) as $imgs | [
.annotations[]
| select(.attributes.type == "letter")
| $imgs[.image_id] + {label: .label}
]
Online demo
Trying to make our dashboard as code while using CloudFormation. Getting an error while validating template with the embedded JSON String inside the YML File. It is having problems with the "SEARCH('{AWS/EC2,InstanceId) fields saying those are invalid strings. I have ran it through a JSON Linter and works fine. I have also deployed the CloudWatch Dashboard console just fine with the JSON.
Question:
Is there anyway to just wrap this section as a string for CloudFormation in the YML file so it doesn't get tripped up on the JSON string contents?
Example:
DetailedDashboard:
Type: "AWS::CloudWatch::Dashboard"
Properties:
DashboardName: "DetailedDashboard"
DashboardBody: !Sub
...,
{
"type": "metric",
"x": 6,
"y": 18,
"width": 6,
"height": 6,
"properties": {
"metrics": [
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkIn', 'Average', 300)", "id": "network_in", "period": 300, "region": "us-east-1", "label": "net_in" } ],
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkOut', 'Average', 300)", "id": "network_out", "period": 300, "region": "us-east-1", "label": "net_out" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "us-east-1",
"title": "Network in/out by Host",
"stat": "Average",
"period": 300,
"yAxis": {
"left": {
"label": "bytes"
}
}
}
},
DetailedDashboard:
Type: 'AWS::CloudWatch::Dashboard'
Properties:
DashboardName: 'DetailedDashboard'
DashboardBody: !Sub |
{
"type": "metric",
"x": 6,
"y": 18,
"width": 6,
"height": 6,
"properties": {
"metrics": [
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkIn', 'Average', 300)", "id": "network_in", "period": 300, "region": "us-east-1", "label": "net_in" } ],
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkOut', 'Average', 300)", "id": "network_out", "period": 300, "region": "us-east-1", "label": "net_out" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "us-east-1",
"title": "Network in/out by Host",
"stat": "Average",
"period": 300,
"yAxis": {
"left": {
"label": "bytes"
}
}
}
},
I have parent comments and child comments. I want to be able to group together my child comments as one object that is part of my Parent object. Here is my Neo4j code:
MATCH (c:Comment)<-[:COMMENTED_ON]-(cc:Comment)
WHERE c.GUID=$GUID
RETURN collect({comment: c, subcomment: cc})
And here is the JSON output that I receive:
[
{
"parentComment": {
"identity": {
"low": 6418,
"high": 0
},
"labels": [
"Action",
"Comment"
],
"properties": {
"GUID": "77750e90-77cf-4e40-9753-87ba828366a5",
"text": "This is a comment",
"type": "Comment",
"timestamp": 20171220111906416
}
},
"childComment": {
"identity": {
"low": 8404,
"high": 0
},
"labels": [
"Comment"
],
"properties": {
"user": "James",
"text": "Test comment",
"timestamp": 20180314142848576
}
}
},
{
"parentComment": {
"identity": {
"low": 6418,
"high": 0
},
"labels": [
"Action",
"Comment"
],
"properties": {
"GUID": "77750e90-77cf-4e40-9753-87ba828366a5",
"text": "This is a comment",
"type": "Comment",
"timestamp": 20171220111906416
}
},
"childComment": {
"identity": {
"low": 8659,
"high": 0
},
"labels": [
"Comment"
],
"properties": {
"user": "James S",
"text": "TEST",
"timestamp": "today"
}
}
}
]
As you can see it is printing the parent comment twice with a different child each time. What do I need to include in my Cypher query to group the child nodes together?
You want to return a map projection, this way:
MATCH (c:Comment)<-[:COMMENTED_ON]-(cc:Comment)
WHERE c.GUID=$GUID
RETURN {comment : c, subcomments: collect(cc)}
If I had the following code below, how would I display the usernames under likes? at the moment I use photo.images.low_resolution.url to show me the urk of the low resolution image but I can't figure out likes section.
{
"data": [{
"location": {
"id": "833",
"latitude": 37.77956816727314,
"longitude": -122.41387367248539,
"name": "Civic Center BART"
},
"comments": {
"count": 16,
"data": [ ... ]
},
"caption": null,
"link": "http://instagr.am/p/BXsFz/",
"likes": {
"count": 190,
"data": [{
"username": "shayne",
"full_name": "Shayne Sweeney",
"id": "20",
"profile_picture": "..."
}, {...subset of likers...}]
},
"created_time": "1296748524",
"images": {
"low_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_5.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_7.jpg",
"width": 612,
"height": 612
}
},
"type": "image",
"filter": "Earlybird",
"tags": [],
"id": "22987123",
"user": {
"username": "kevin",
"full_name": "Kevin S",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
"id": "3"
}
},
...]
}
See this jsFiddle. Note the second entry has no data.
Please:
//photo = your object
//Make sure to remove empty objects({...}) as in your code example.
for (var i = 0; i < photo.data.length; i++) {
var photoData = photo.data[i];
for (var x = 0; x < photoData.likes.data.length; x++) {
//Do what ever you want with the like's user...
var likeData = photoData.likes.data[x];
alert(likeData.username);
}
}
And next time use console.log to navigate through your objects: