JQ Select Outer Objects and Child Based on Child - json

I am trying to select the credentials object and specific parent level objects only if the key credhub-ref exist within the credential object following JSON:
{
"total_results": 23,
"total_pages": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"guid": "cd",
"url": "/v2/service_bindings/cd",
"created_at": "2019-03-04T21:18:53Z",
"updated_at": "2019-03-04T21:18:53Z"
},
"entity": {
"app_guid": "9c",
"service_instance_guid": "66",
"credentials": {
"credhub-ref": "/c/54"
},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2019-03-04T21:18:53Z",
"created_at": "2019-03-04T21:18:53Z"
},
"app_url": "/v2/apps/9c",
"service_instance_url": "/v2/service_instances/66",
"service_binding_parameters_url": "/v2/service_bindings/cd"
}
},
{
"metadata": {
"guid": "cd",
"url": "/v2/service_bindings/cd",
"created_at": "2019-03-11T08:49:22Z",
"updated_at": "2019-03-11T08:49:22Z"
},
"entity": {
"app_guid": "ea",
"service_instance_guid": "86",
"credentials": {},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2019-03-11T08:49:22Z",
"created_at": "2019-03-11T08:49:22Z"
},
"app_url": "/v2/apps/ea",
"service_instance_url": "/v2/service_instances/86",
"service_binding_parameters_url": "/v2/service_bindings/cd"
}
},
{
"metadata": {
"guid": "e0",
"url": "/v2/service_bindings/e0",
"created_at": "2019-03-19T20:07:25Z",
"updated_at": "2019-03-19T20:07:25Z"
},
"entity": {
"app_guid": "73",
"service_instance_guid": "52",
"credentials": {
"hostname": "10.13.7.64",
"port": 3306,
"name": "cf_52",
"username": "w",
"password": "w",
"uri": "mysql://",
"jdbcUrl": "jdbc:mysql://10.193.78.64:"
},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2019-03-19T20:07:25Z",
"created_at": "2019-03-19T20:07:25Z"
},
"app_url": "/v2/apps/73",
"service_instance_url": "/v2/service_instances/52",
"service_binding_parameters_url": "/v2/service_bindings/e0"
}
},
{
"metadata": {
"guid": "18",
"url": "/v2/service_bindings/18",
"created_at": "2019-03-19T20:07:27Z",
"updated_at": "2019-03-19T20:07:27Z"
},
"entity": {
"app_guid": "73",
"service_instance_guid": "ae",
"credentials": {
"credhub-ref": "/c/54"
},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2019-03-19T20:07:27Z",
"created_at": "2019-03-19T20:07:27Z"
},
"app_url": "/v2/apps/73",
"service_instance_url": "/v2/service_instances/aec",
"service_binding_parameters_url": "/v2/service_bindings/18"
}
}
]
}
The current query only returns the credentials object:
jq '.resources[].entity.credentials | select(.["credhub-ref"])' test.json
Results in:
{
"credhub-ref": "/c/42"
}
{
"credhub-ref": "/c/54"
}
I need a query that outputs the parent objects app_guid and service_instance_guid too like the following:
}
"app_guid": "9c",
"service_instance_guid": "66",
"credentials": {
"credhub-ref": "/c/54"
},
{
"app_guid": "73",
"service_instance_guid": "ae",
"credentials": {
"credhub-ref": "/c/54"
}
A few good examples of how this can be done would go a long way for helping me better understand how JQ works.

This is one of many ways way to get the expected output:
jq '.resources[].entity | select(.credentials."credhub-ref") | {app_guid, service_instance_guid, credentials}' test.json
It will search for .credentials.credhub-ref in every entity object and will return app_guid, service_instance_guid, credentials as object if found.
Output:
{
"app_guid": "9c",
"service_instance_guid": "66",
"credentials": {
"credhub-ref": "/c/54"
}
}
{
"app_guid": "73",
"service_instance_guid": "ae",
"credentials": {
"credhub-ref": "/c/54"
}
}

Related

Check if a key exists and return another key

I need help with jq syntax on how to return the Gitlab job ID if it contains an artifact. The JSON output looks like this (removed a lot of unrelated info from it and added [...]):
[{
"id": 3219589880,
"status": "success",
"stage": "test",
"name": "job_with_no_artifact",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.119Z",
"started_at": "2022-10-24T18:21:25.986Z",
"finished_at": "2022-10-24T18:21:38.464Z",
"duration": 12.478682,
"queued_duration": 0.499786,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
"pipeline": {
"id": 123456789,
[...]
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts": [],
"runner": {
"id": 12270859,
[...]
},
"artifacts_expire_at": null,
"tag_list": []
}, {
"id": 3219589878,
"status": "success",
"stage": "test",
"name": "create_artifact_job_2",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.111Z",
"started_at": "2022-10-24T18:21:25.922Z",
"finished_at": "2022-10-24T18:21:39.090Z",
"duration": 13.168405,
"queued_duration": 0.464364,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
},
"pipeline": {
"id": 675641982,
[...],
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts_file": {
"filename": "artifacts.zip",
"size": 223
},
"artifacts": [{
"file_type": "archive",
"size": 223,
"filename": "artifacts.zip",
"file_format": "zip"
}, {
"file_type": "metadata",
"size": 153,
"filename": "metadata.gz",
"file_format": "gzip"
}],
"runner": {
"id": 12270845,
[...]
},
"artifacts_expire_at": "2022-10-25T18:21:35.859Z",
"tag_list": []
}, {
"id": 3219589876,
"status": "success",
"stage": "test",
"name": "create_artifact_job_1",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.103Z",
"started_at": "2022-10-24T18:21:25.503Z",
"finished_at": "2022-10-24T18:21:41.407Z",
"duration": 15.904028,
"queued_duration": 0.098837,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
},
"pipeline": {
"id": 123456789,
[...]
},
"web_url": "WEB_URL",
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts_file": {
"filename": "artifacts.zip",
"size": 217
},
"artifacts": [{
"file_type": "archive",
"size": 217,
"filename": "artifacts.zip",
"file_format": "zip"
}, {
"file_type": "metadata",
"size": 152,
"filename": "metadata.gz",
"file_format": "gzip"
}],
"runner": {
"id": 12270857,
},
"artifacts_expire_at": "2022-10-25T18:21:37.808Z",
"tag_list": []
}]
I've been trying to do either of the following using jQ:
Either:
Check if artifacts_file key exists in each iteration and if it does return the (job) id (so .[].id)
Check if artifacts array is empty in each iteration and if it is empty return the (job) id.
In both cases I'm able to do the first part but I am not sure how to return the .id key.
Related stackoverflow questions that I've been trying to utilize and adapt to my case:
jq - return array value if its length is not null
How to check for presence of 'key' in jq before iterating over the values
What I have so far: jq '[.[].artifacts[]|select(length > 0)] | .[]' which returns all the artifacts found (but it doesn't contain the .id of the job).
Checking the existence of a field using has:
.[] | select(has("artifacts_file")).id
3219589878
3219589876
Demo
Checking if a field is an empty array by comparing it to []:
.[] | select(.artifacts == []).id
3219589880
Demo

Chainlink multi-variable responses - results not getting appended

I'm trying to implement a multi-variable job on my local node, however I'm finding that only 1 of the 3 results are being added to the chainlink_result_collection array in the resultcollect task. My definition is very similar to the example one linked, the main difference being the use of an external adapter
Running the above example smart contract and spec on my node works, and gives the following output. Take note of the chainlink_result_collection array being appended to after each run. Have linked the output file to stay under the 30k size limit for SO posts
However when I try to run my multi-variable job, I get the following output. Take note of the chainlink_result_collection after each resultcollect task. You can see each time it's being set to the latest return value, instead of being appended to like the previous job output. So the length of the chainlink_result_collection array at the end is 1 instead of 3 elements
{
"id": "c27b2627-3aeb-4acb-8b84-1e191854b25d",
"jobId": "332118053343434c8d519e4c3a8c3fef",
"result": {
"data": {
"result": "0x0000000000000000000000000000000000000000000000020000000000002060",
"address": "0xb6EFEcE462EA6118A0A7EC1F2a3c7033b1F82967",
"dataPrefix": "0xc23231a259fa1d606b3b1f8d31d6b169af467af60dbf0ac4e0014eb49553ccc70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f08086217d2ab6f717fd7a12cd3c53a94efa6761b2cdfe81000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061288b88",
"unixDateTime": "1625097600",
"functionSelector": "0x4ab0d190",
"aggregatorAddress": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"__chainlink_result_collection__": [
"0x0000000000000000000000000000000000000000000000020000000000002060"
]
},
"error": "insertEthTx failed while constructing EthTx data: number of collectors 2 != number of types in ABI encoding 4"
},
"status": "errored",
"taskRuns": [
{
"id": "5b7a842a-c5bb-47bb-86d6-9ffc9a8d6288",
"result": {
"data": {
"address": "0xb6EFEcE462EA6118A0A7EC1F2a3c7033b1F82967",
"dataPrefix": "0xc23231a259fa1d606b3b1f8d31d6b169af467af60dbf0ac4e0014eb49553ccc70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f08086217d2ab6f717fd7a12cd3c53a94efa6761b2cdfe81000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061288b88",
"roundAnswer": "36893488147419111519",
"unixDateTime": "1625097600",
"functionSelector": "0x4ab0d190",
"laterRoundAnswer": "36893488147419111520",
"aggregatorAddress": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"earlierRoundAnswer": "36893488147419111518"
},
"error": null
},
"status": "completed",
"task": {
"ID": 83,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "historical-price",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.169781+09:30",
"UpdatedAt": "2021-08-27T16:16:00.169781+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 3
},
{
"id": "ce1394bd-5d9e-4150-8fd2-7d251b69a81d",
"result": {
"data": {
"result": "36893488147419111519"
},
"error": null
},
"status": "completed",
"task": {
"ID": 84,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "copy",
"confirmations": null,
"params": {
"copyPath": [
"roundAnswer"
]
},
"CreatedAt": "2021-08-27T16:16:00.170343+09:30",
"UpdatedAt": "2021-08-27T16:16:00.170343+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "da32538d-b640-4bcb-8acb-fe9aafa344b0",
"result": {
"data": {
"result": "0x000000000000000000000000000000000000000000000002000000000000205f"
},
"error": null
},
"status": "completed",
"task": {
"ID": 85,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethuint256",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.170885+09:30",
"UpdatedAt": "2021-08-27T16:16:00.170885+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "372cdf12-8752-492c-9c2d-ff3354d878af",
"result": {
"data": {
"result": "0x000000000000000000000000000000000000000000000002000000000000205f",
"address": "0xb6EFEcE462EA6118A0A7EC1F2a3c7033b1F82967",
"dataPrefix": "0xc23231a259fa1d606b3b1f8d31d6b169af467af60dbf0ac4e0014eb49553ccc70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f08086217d2ab6f717fd7a12cd3c53a94efa6761b2cdfe81000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061288b88",
"unixDateTime": "1625097600",
"functionSelector": "0x4ab0d190",
"aggregatorAddress": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"__chainlink_result_collection__": [
"0x000000000000000000000000000000000000000000000002000000000000205f"
]
},
"error": null
},
"status": "completed",
"task": {
"ID": 86,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "resultcollect",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.171458+09:30",
"UpdatedAt": "2021-08-27T16:16:00.171458+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "0c8e18c2-c352-4af0-a282-a19fbcf03c2d",
"result": {
"data": {
"address": "0xb6EFEcE462EA6118A0A7EC1F2a3c7033b1F82967",
"dataPrefix": "0xc23231a259fa1d606b3b1f8d31d6b169af467af60dbf0ac4e0014eb49553ccc70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f08086217d2ab6f717fd7a12cd3c53a94efa6761b2cdfe81000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061288b88",
"roundAnswer": "36893488147419111519",
"unixDateTime": "1625097600",
"functionSelector": "0x4ab0d190",
"laterRoundAnswer": "36893488147419111520",
"aggregatorAddress": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"earlierRoundAnswer": "36893488147419111518"
},
"error": null
},
"status": "completed",
"task": {
"ID": 87,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "historical-price",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.172138+09:30",
"UpdatedAt": "2021-08-27T16:16:00.172138+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "48482e08-bed1-4956-8aa8-3ff6f2d9f38d",
"result": {
"data": {
"result": "36893488147419111518"
},
"error": null
},
"status": "completed",
"task": {
"ID": 88,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "copy",
"confirmations": null,
"params": {
"copyPath": [
"earlierRoundAnswer"
]
},
"CreatedAt": "2021-08-27T16:16:00.172638+09:30",
"UpdatedAt": "2021-08-27T16:16:00.172638+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "825ed16c-b662-4fb2-ac2d-abeee3259cfc",
"result": {
"data": {
"result": "0x000000000000000000000000000000000000000000000002000000000000205e"
},
"error": null
},
"status": "completed",
"task": {
"ID": 89,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethuint256",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.173151+09:30",
"UpdatedAt": "2021-08-27T16:16:00.173151+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "58ade305-bc91-4542-83b5-8b4e0018eebf",
"result": {
"data": {
"result": "0x000000000000000000000000000000000000000000000002000000000000205e",
"address": "0xb6EFEcE462EA6118A0A7EC1F2a3c7033b1F82967",
"dataPrefix": "0xc23231a259fa1d606b3b1f8d31d6b169af467af60dbf0ac4e0014eb49553ccc70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f08086217d2ab6f717fd7a12cd3c53a94efa6761b2cdfe81000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061288b88",
"unixDateTime": "1625097600",
"functionSelector": "0x4ab0d190",
"aggregatorAddress": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"__chainlink_result_collection__": [
"0x000000000000000000000000000000000000000000000002000000000000205e"
]
},
"error": null
},
"status": "completed",
"task": {
"ID": 90,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "resultcollect",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.173677+09:30",
"UpdatedAt": "2021-08-27T16:16:00.173677+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "d7982f84-03be-4f41-a6ad-ee487c84fc6b",
"result": {
"data": {
"address": "0xb6EFEcE462EA6118A0A7EC1F2a3c7033b1F82967",
"dataPrefix": "0xc23231a259fa1d606b3b1f8d31d6b169af467af60dbf0ac4e0014eb49553ccc70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f08086217d2ab6f717fd7a12cd3c53a94efa6761b2cdfe81000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061288b88",
"roundAnswer": "36893488147419111519",
"unixDateTime": "1625097600",
"functionSelector": "0x4ab0d190",
"laterRoundAnswer": "36893488147419111520",
"aggregatorAddress": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"earlierRoundAnswer": "36893488147419111518"
},
"error": null
},
"status": "completed",
"task": {
"ID": 91,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "historical-price",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.174159+09:30",
"UpdatedAt": "2021-08-27T16:16:00.174159+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "cf3a1caa-723e-4b2f-ae50-6096007dd02e",
"result": {
"data": {
"result": "36893488147419111520"
},
"error": null
},
"status": "completed",
"task": {
"ID": 92,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "copy",
"confirmations": null,
"params": {
"copyPath": [
"laterRoundAnswer"
]
},
"CreatedAt": "2021-08-27T16:16:00.174617+09:30",
"UpdatedAt": "2021-08-27T16:16:00.174617+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "53d76d5c-01b2-4e0d-8515-9f1a4901635b",
"result": {
"data": {
"result": "0x0000000000000000000000000000000000000000000000020000000000002060"
},
"error": null
},
"status": "completed",
"task": {
"ID": 93,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethuint256",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.175071+09:30",
"UpdatedAt": "2021-08-27T16:16:00.175071+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "1fb908bb-9539-4617-9395-4e5796e214c2",
"result": {
"data": {
"result": "0x0000000000000000000000000000000000000000000000020000000000002060",
"address": "0xb6EFEcE462EA6118A0A7EC1F2a3c7033b1F82967",
"dataPrefix": "0xc23231a259fa1d606b3b1f8d31d6b169af467af60dbf0ac4e0014eb49553ccc70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f08086217d2ab6f717fd7a12cd3c53a94efa6761b2cdfe81000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061288b88",
"unixDateTime": "1625097600",
"functionSelector": "0x4ab0d190",
"aggregatorAddress": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"__chainlink_result_collection__": [
"0x0000000000000000000000000000000000000000000000020000000000002060"
]
},
"error": null
},
"status": "completed",
"task": {
"ID": 94,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "resultcollect",
"confirmations": null,
"params": {
},
"CreatedAt": "2021-08-27T16:16:00.175515+09:30",
"UpdatedAt": "2021-08-27T16:16:00.175515+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
},
{
"id": "8763850e-80a6-4a1b-af04-aabfb69ff2c9",
"result": {
"data": {
},
"error": "insertEthTx failed while constructing EthTx data: number of collectors 2 != number of types in ABI encoding 4"
},
"status": "errored",
"task": {
"ID": 95,
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethtx",
"confirmations": 1,
"params": {
"abiEncoding": [
"bytes32",
"uint80",
"uint80",
"uint80"
]
},
"CreatedAt": "2021-08-27T16:16:00.175982+09:30",
"UpdatedAt": "2021-08-27T16:16:00.175982+09:30",
"DeletedAt": null
},
"minimumConfirmations": 3,
"confirmations": 1
}
],
"createdAt": "2021-08-27T16:16:52.308136+09:30",
"finishedAt": "2021-08-27T16:18:59.22246+09:30",
"updatedAt": "2021-08-27T16:18:59.259186+09:30",
"creationHeight": "26956178",
"observedHeight": "26956180",
"payment": "0",
"initiator": {
"id": 7,
"jobSpecId": "33211805-3343-434c-8d51-9e4c3a8c3fef",
"type": "runlog",
"params": {
"address": "0xb6efece462ea6118a0a7ec1f2a3c7033b1f82967"
}
},
"type": "Direct request job run"
}
This is my job definition:
{
"name": "multi-word2",
"initiators": [
{
"id": 7,
"jobSpecId": "33211805-3343-434c-8d51-9e4c3a8c3fef",
"type": "runlog",
"params": {
"address": "0xb6efece462ea6118a0a7ec1f2a3c7033b1f82967"
}
}
],
"tasks": [
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "historical-price"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "copy",
"params": {
"copyPath": [
"roundAnswer"
]
}
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethuint256"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "resultcollect"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "historical-price"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "copy",
"params": {
"copyPath": [
"earlierRoundAnswer"
]
}
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethuint256"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "resultcollect"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "historical-price"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "copy",
"params": {
"copyPath": [
"laterRoundAnswer"
]
}
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethuint256"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "resultcollect"
},
{
"jobSpecId": "332118053343434c8d519e4c3a8c3fef",
"type": "ethtx",
"confirmations": 1,
"params": {
"abiEncoding": [
"bytes32",
"uint80",
"uint80",
"uint80"
]
}
}
]
}
the issue is that the 'chainlink_result_collection' array is not passed through from the resultsCollect to the EA (external adapter) call, whereas it is from resultsCollect to a normal HTTP Get task. I verified this by creating a job that contains 3 requests (EA, HTTPGET, EA), and observed that at the resultsCollect for the HTTPGet, the array correctly had 2 values, however on the final request (EA), the array didn't get passed through to the EA task, and the end result was just the 1 return value from the final EA
There's an open issue on this at the Chainlink GitHub

Kubernetes + jq - retrieving containers list per pod yields cartesian product

Im trying to use jq on kubernetes json output, to create new json object containing list of objects - container and image per pod, however im getting cartesian product.
my input data (truncated from sensitive info):
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"creationTimestamp": "2021-06-30T12:45:40Z",
"name": "pod-1",
"namespace": "default",
"resourceVersion": "757679286",
"selfLink": "/api/v1/namespaces/default/pods/pod-1"
},
"spec": {
"containers": [
{
"image": "image-1",
"imagePullPolicy": "Always",
"name": "container-1",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"readOnly": true
}
]
},
{
"image": "image-2",
"imagePullPolicy": "Always",
"name": "container-2",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"readOnly": true
}
]
}
],
"dnsPolicy": "ClusterFirst",
"enableServiceLinks": true,
"priority": 0,
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"serviceAccount": "default",
"serviceAccountName": "default",
"terminationGracePeriodSeconds": 30,
"tolerations": [
{
"effect": "NoExecute",
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"tolerationSeconds": 300
},
{
"effect": "NoExecute",
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"tolerationSeconds": 300
}
],
"volumes": [
{
"name": "default-token-b954f",
"secret": {
"defaultMode": 420,
"secretName": "default-token-b954f"
}
}
]
},
"status": {
"conditions": [
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"message": "containers with unready status: [container-1 container-2]",
"reason": "ContainersNotReady",
"status": "False",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"message": "containers with unready status: [container-1 container-2]",
"reason": "ContainersNotReady",
"status": "False",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"status": "True",
"type": "PodScheduled"
}
],
"containerStatuses": [
{
"image": "image-1",
"imageID": "",
"lastState": {},
"name": "container-1",
"ready": false,
"restartCount": 0,
"started": false,
"state": {
"waiting": {
"message": "Back-off pulling image \"image-1\"",
"reason": "ImagePullBackOff"
}
}
},
{
"image": "image-2",
"imageID": "",
"lastState": {},
"name": "container-2",
"ready": false,
"restartCount": 0,
"started": false,
"state": {
"waiting": {
"message": "Back-off pulling image \"image-2\"",
"reason": "ImagePullBackOff"
}
}
}
],
"qosClass": "BestEffort",
"startTime": "2021-06-30T12:45:40Z"
}
}
],
"kind": "List",
"metadata": {
"resourceVersion": "",
"selfLink": ""
}
}
my command:
jq '.items[] | { "name": .metadata.name, "containers": [{ "name": .spec.containers[].name, "image": .spec.containers[].image }]} '
desired output:
{
"name": "pod_1",
"containers": [
{
"name": "container_1",
"image": "image_1"
},
{
"name": "container_2",
"image": "image_2"
}
]
}
output I get:
{
"name": "pod-1",
"containers": [
{
"name": "container-1",
"image": "image-1"
},
{
"name": "container-1",
"image": "image-2"
},
{
"name": "container-2",
"image": "image-1"
},
{
"name": "container-2",
"image": "image-2"
}
]
}
Could anyone explain what am I doing wrong?
Best Regards, Piotr.
The problem is "name": .spec.containers[].name and "image": .spec.containers[].image:
Both expressions generate a sequence of each value for name and image which will than be combined.
Simplified example of why you get a Cartesian product:
jq -c -n '{name: ("A", "B"), value: ("C", "D")}'
outputs:
{"name":"A","value":"C"}
{"name":"A","value":"D"}
{"name":"B","value":"C"}
{"name":"B","value":"D"}
You get the desired output using this jq filter on your input:
jq '
.items[]
| {
"name": .metadata.name,
"containers": .spec.containers
| map({name, image})
}'
output:
{
"name": "pod-1",
"containers": [
{
"name": "container-1",
"image": "image-1"
},
{
"name": "container-2",
"image": "image-2"
}
]
}

Firebase: JSON payload not accepted

I'm trying to push JSON from a service in to Firebase, and it's not accepting it.
I cant figure out why. JSONLint validates it as valid.
The error I get is:
error: "Invalid data; couldn't parse JSON object, array, or value."
Here's the JSON payload:
{
"app_id": "e4805b8d5a9f4032b0bb8b6d9c6726b8",
"archived": false,
"attachments": {
"form.xml": {
"content_type": "text/xml",
"length": 4500,
"url": "https://someurl.com/form.xml"
}
},
"build_id": "3c5703e20346462ebcb07a3f36d5fe9b",
"domain": "my-test",
"edited_by_user_id": null,
"edited_on": null,
"form": {
"#type": "data",
"#name": "Beneficiary Registration",
"#uiVersion": "1",
"#version": "1",
"#xmlns": "http://openrosa.org/formdesigner/123456",
"beneficiary_age": {
"beneficiary_age_num": "8",
"beneficiary_exact_age_ind": "N"
},
"beneficiary_gender_cd": "M",
"beneficiary_id": "Hhr-O6I3C5L-J3G1L",
"case": {
"#case_id": "a07972bc-1a34-4c84-90ea-91250639f2a4",
"#date_modified": "2020-03-17T20:57:26.986000Z",
"#user_id": "2275c340c48ac83b6852035b0a15b5d3",
"#xmlns": "http://someurl.org/case/transaction/v2"
},
"case_name": "Hhr-O6I3C5L-J3G1L|joel galager|Katsekera|Katsekera|Mpando|Katsekera|KE",
"existing_beneficiaries": "Jane Doe\n\nJoan Doe",
"existing_beneficiaries_label": "",
"household_information": {
"beneficiary_household_information_display": "",
"beneficiary_location_hierarchy_1": "KE",
"beneficiary_location_hierarchy_1_text": "Kenya",
"beneficiary_location_hierarchy_2": "HF0001",
"beneficiary_location_hierarchy_2_text": "Katsekera",
"beneficiary_location_hierarchy_3": "TA0001",
"beneficiary_location_hierarchy_3_text": "Mpando",
"beneficiary_location_hierarchy_4": "GHV0001",
"beneficiary_location_hierarchy_4_text": "Katsekera",
"beneficiary_location_hierarchy_5": "V0001",
"beneficiary_location_hierarchy_5_text": "Katsekera",
"correct_information": "",
"hh_first_name": "John",
"hh_full_name": "John Doe",
"hh_id_fk": "Hhr-O6I3C5L",
"hh_last_name": "Doe",
"household_information": ""
},
"meta": {
"#xmlns": "http://openrosa.org/jr/xforms",
"appVersion": "Formplayer Version: 2.47",
"app_build_version": 1,
"commcare_version": null,
"deviceID": "Formplayer",
"drift": "0",
"geo_point": null,
"instanceID": "123-321-232",
"timeEnd": "2020-03-17T20:57:26.986000Z",
"timeStart": "2020-03-17T20:57:13.958000Z",
"userID": "2275c340c48ac83b6852035b0a15b5d3",
"username": "some_username"
},
"name_group": {
"beneficiary_first_name": "joel",
"beneficiary_full_name": "joel galager",
"beneficiary_last_name": "galager"
},
"subcase_0": {
"case": {
"#case_id": "2a4bfe27-a5c3-4f3a-8540-5f8ded86db85",
"#date_modified": "2020-03-17T20:57:26.986000Z",
"#user_id": "abc123",
"#xmlns": "http://commcarehq.org/case/transaction/v2",
"create": {
"case_name": "Hhr-O6I3C5L-J3G1L|joel galager|Katsekera|Katsekera|Mpando|Katsekera|KE",
"case_type": "beneficiary_case",
"owner_id": "abc123"
},
"index": {
"parent": {
"#text": "a07972bc-1a34-4c84-90ea-91250639f2a4",
"#case_type": "household_case"
}
},
"update": {
"beneficiary_age_num": "8",
"beneficiary_exact_age_ind": "N",
"beneficiary_first_name": "joel",
"beneficiary_full_name": "joel galager",
"beneficiary_gender_cd": "M",
"beneficiary_id": "Hhr-O6I3C5L-J3G1L",
"beneficiary_last_name": "galager",
"beneficiary_location_hierarchy_1": "KE",
"beneficiary_location_hierarchy_1_text": "Kenya",
"beneficiary_location_hierarchy_2": "HF0001",
"beneficiary_location_hierarchy_2_text": "Katsekera",
"beneficiary_location_hierarchy_3": "TA0001",
"beneficiary_location_hierarchy_3_text": "Mpando",
"beneficiary_location_hierarchy_4": "GHV0001",
"beneficiary_location_hierarchy_4_text": "Katsekera",
"beneficiary_location_hierarchy_5": "V0001",
"beneficiary_location_hierarchy_5_text": "Katsekera",
"hh_id_fk": "Hhr-O6I3C5L"
}
}
}
},
"id": "d547ccea-503c-4c50-b974-38ed564ae78a",
"indexed_on": "2020-03-17T21:01:04.695654",
"initial_processing_complete": true,
"is_phone_submission": true,
"metadata": {
"appVersion": "Formplayer Version: 2.47",
"app_build_version": 1,
"commcare_version": null,
"deviceID": "Formplayer",
"drift": "0",
"geo_point": null,
"instanceID": "01010101",
"location": null,
"timeEnd": "2020-03-17T20:57:26.986000Z",
"timeStart": "2020-03-17T20:57:13.958000Z",
"userID": "2275c340c48ac83b6852035b0a15b5d3",
"username": "myusername"
},
"problem": null,
"received_on": "2020-03-17T20:57:27.179986Z",
"resource_uri": "",
"server_modified_on": "2020-03-17T20:57:27.382548Z",
"type": "data",
"uiversion": "1",
"version": "1"
}
This is probably because of #type inside form.
The # character can't be used in RTDB paths.
See How data is structured from the docs.
Keys cannot contain
.
$
#
[
]
/
ASCII control characters 0-31 or 127

Filtering output to needed values in json

I have below output generated as part of gathering all attributes about openstack VM. I am trying to work a json filter, which would let me select just values of interest. (tenant name, tenant ID or cloud name and so on).
I am new to filters, so all the help is appreciated. I tried different ways but not close to what i want.
N_ID": true,
"NAME_ATTR": "name",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "cloud-b",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"OS-SRV-USG:launched_at": "2018-06-05T22:45:50.000000",
"OS-SRV-USG:terminated_at": null,
"accessIPv4": "192.168.0.1",
"accessIPv6": "",
"addresses": {
"tenant-internal-direct-net": [
{
"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:73:c6:9e",
"OS-EXT-IPS:type": "fixed",
"addr": "192.168.0.1",
"version": 4
}
]
},
"az": "cloud-1-b",
"cloud": "cloud-1",
"config_drive": "",
"created": "2018-06-05T22:45:37Z",
"flavor": {
"id": "15",
"name": "2vCPUx8GB"
},
"hostId": "f12acb7a6a4050672a7710da4ccb5987916ac46648fc667496c4a169",
"human_id": "myhost-ost1",
"id": "ae12d6cd-c9b8-4908-a0f9-6af614f01197",
"image": {
"id": ""
},
"interface_ip": "192.168.0.1",
"key_name": "pz-rhel7",
"metadata": {},
"name": "myhost-ost1",
"networks": {
"tenant-internal-direct-net": [
"192.168.0.1"
]
},
"os-extended-volumes:volumes_attached": [
{
"id": "179749a7-ba9b-4cc1-aebd-dcc8dcb7f4e1"
}
],
"private_v4": "",
"progress": 0,
"public_v4": "192.168.0.1",
"public_v6": "",
"region": "cloud-1",
"request_ids": [],
"security_groups": [
{
"description": "",
"id": "55991c66-beb5-4750-b8f6-06025a1ce7d4",
"name": "SSHping",
"security_group_rules": [
{
"direction": "ingress",
"ethertype": "IPv4",
"id": "53fa8fca-d54c-4462-9f5e-a748fed86885",
"port_range_max": null,
"port_range_min": null,
"protocol": "icmp",
"remote_ip_prefix": "0.0.0.0/0",
"security_group_id": "55991c66-beb5-4750-b8f6-06025a1ce7d4"
},
{
"direction": "ingress",
"ethertype": "IPv4",
"id": "841446f5-a7bf-46e9-91c2-f505c5842bc6",
"port_range_max": 22,
"port_range_min": 22,
"protocol": "tcp",
"remote_ip_prefix": "0.0.0.0/0",
"security_group_id": "55991c66-beb5-4750-b8f6-06025a1ce7d4"
}
]
},
{
"description": "Default security group",
"id": "987efb61-d7f3-47d5-9362-42f66d1b104b",
"name": "default",
"security_group_rules": [
{
"direction": "ingress",
"ethertype": "IPv4",
"id": "79da1cc2-2128-4937-95ca-d0fc757bbfb3",
"port_range_max": 22,
"port_range_min": 22,
"protocol": "tcp",
"remote_ip_prefix": "0.0.0.0/0",
"security_group_id": "987efb61-d7f3-47d5-9362-42f66d1b104b"
},
{
"direction": "ingress",
"ethertype": "IPv4",
"id": "901d230e-9cd5-486c-aa89-c279b359fac9",
"port_range_max": 1,
"port_range_min": 1,
"protocol": "tcp",
"remote_ip_prefix": "0.0.0.0/0",
"security_group_id": "987efb61-d7f3-47d5-9362-42f66d1b104b"
},
{
"direction": "ingress",
"ethertype": "IPv4",
"id": "950c6b8c-e129-4138-8dd5-92254c5bd6c8",
"port_range_max": null,
"port_range_min": null,
"protocol": null,
"remote_ip_prefix": null,
"security_group_id": "987efb61-d7f3-47d5-9362-42f66d1b104b"
},
{
"direction": "ingress",
"ethertype": "IPv4",
"id": "cf20d16d-0b8a-4bd7-b6b4-cab6d5968a44",
"port_range_max": null,
"port_range_min": null,
"protocol": null,
"remote_ip_prefix": null,
"security_group_id": "987efb61-d7f3-47d5-9362-42f66d1b104b"
}
]
}
],
"status": "ACTIVE",
"tenant_id": "99f1f837a8004092926887d46188e726",
"updated": "2018-06-05T22:45:50Z",
"user_id": "35f6e9300037f9c6d23f08c5af8b324c4ab23688d2a146bd6aac601377ed72ef",
"volumes": [
{
"HUMAN_ID": false,
"NAME_ATTR": "name",
"attachments": [
{
"attached_at": "2018-06-05T22:45:43.000000",
"attachment_id": "4602ad6b-8652-4702-910b-e4e82a894a32",
"device": "/dev/vda",
"host_name": null,
"id": "179749a7-ba9b-4cc1-aebd-dcc8dcb7f4e1",
"server_id": "ae12d6cd-c9b8-4908-a0f9-6af614f01197",
"volume_id": "179749a7-ba9b-4cc1-aebd-dcc8dcb7f4e1"
}
],
"availability_zone": "nova",
"bootable": true,
"consistencygroup_id": null,
"created_at": "2018-06-05T22:45:39.000000",
"description": "",
"device": "/dev/vda",
"display_description": "",
"display_name": "",
"encrypted": false,
"human_id": null,
"id": "179749a7-ba9b-4cc1-aebd-dcc8dcb7f4e1",
"links": [
{
"href": "http://cloud-1.mycloud.com:8776/v2/99f1f837a8004092926887d46188e726/volumes/179749a7-ba9b-4cc1-aebd-dcc8dcb7f4e1",
"rel": "self"
},
{
"href": "http://cloud-1.mycloud.com:8776/99f1f837a8004092926887d46188e726/volumes/179749a7-ba9b-4cc1-aebd-dcc8dcb7f4e1",
"rel": "bookmark"
}
],
"metadata": {
"attached_mode": "rw",
"readonly": "False"
},
"multiattach": false,
"name": "",
"os-vol-tenant-attr:tenant_id": "99f1f837a8004092926887d46188e726",
"replication_status": "disabled",
"request_ids": [],
"size": 11,
"snapshot_id": null,
"source_volid": null,
"status": "in-use",
"updated_at": "2018-06-05T22:45:43.000000",
"user_id": "35f6e9300037f9c6d23f08c5af8b324c4ab23688d2a146bd6aac601377ed72ef",
"volume_image_metadata": {
"checksum": "2d3f40fa841b1c35c10e74207d1221f8",
"container_format": "bare",
"disk_format": "raw",
"hw_disk_bus": "scsi",
"hw_qemu_guest_agent": "yes",
"hw_scsi_model": "virtio-scsi",
"hw_vif_multiqueue_enabled": "true",
"hw_watchdog_action": "reset",
"image_id": "fe463cc5-fecf-4aad-a77e-70987f421169",
"image_name": "RHEL-7_4-MG",
"min_disk": "0",
"min_ram": "0",
"size": "10737418240"
},
"volume_type": "ceph-standard",
"x_openstack_request_ids": []
}
],
"x_openstack_request_ids": []
}