How to produce a single line output of a record with jq - jq

I have the following JSON
{
"guid": "dce38b4b-9989-42d2-b6bd-702645e344cf",
"name": "dev",
"apps": [
{
"guid": "5d5498cb-a885-4242-a55a-d7d286a1cf48",
"urls": [
"nodered.cloudfoundry.org"
],
"routes": [
{
"guid": "aca4d04b-f99d-4b43-afaa-82ab41afa07c",
"host": "nodered-test",
"port": null,
"path": "",
"domain": {
"guid": "f4b90d7e-2cd3-4d30-b200-f28bbaf6be20",
"name": "cloudfoundry.org"
}
}
],
"service_count": 1,
"service_names": [
"nodered-test-cloudantNoSQLDB"
],
"running_instances": 1,
"name": "perik-nodered-test",
"production": false,
"space_guid": "dce38b4b-9989-42d2-b6bd-702645e344cf",
"stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc",
"buildpack": null,
"detected_buildpack": "SDK for Node.js(TM) (ibm-node.js-6.13.0, buildpack-v3.20-20180403-1426)",
"detected_buildpack_guid": "33e9e82f-8846-4362-a60a-92964285a31e",
"environment_json": {},
"memory": 256,
"instances": 1,
"disk_quota": 1024,
"state": "STARTED",
"version": "8c8c97a0-bc2e-424c-a0a3-d64704feb634",
"command": null,
"console": false,
"debug": null,
"staging_task_id": "539f460c-e4d2-49f9-b5e5-9f4fd31a8370",
"package_state": "STAGED",
"health_check_type": "port",
"health_check_timeout": null,
"health_check_http_endpoint": null,
"staging_failed_reason": null,
"staging_failed_description": null,
"diego": true,
"docker_image": null,
"package_updated_at": "2018-04-10T17:32:06Z",
"detected_start_command": "./vendor/initial_startup.rb",
"enable_ssh": true,
"ports": null
},
{
"guid": "4089ce19-19fb-467b-8876-3635819d5d91",
"urls": [
"nodered.cloudfoundry.org"
],
"routes": [
{
"guid": "b79988d8-5ac5-455d-8fdd-00bc208dd2bc",
"host": "NodeRedTestApp",
"port": null,
"path": "",
"domain": {
"guid": "f4b90d7e-2cd3-4d30-b200-f28bbaf6be20",
"name": "cloudfoundry.org"
}
}
],
"service_count": 1,
"service_names": [
"NodeRedTestApp-cloudantNoSQLDB"
],
"running_instances": 1,
"name": "perik-NodeRedTestApp",
"production": false,
"space_guid": "dce38b4b-9989-42d2-b6bd-702645e344cf",
"stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc",
"buildpack": null,
"detected_buildpack": "SDK for Node.js(TM) (ibm-node.js-6.13.0, buildpack-v3.20-20180403-1426)",
"detected_buildpack_guid": "33e9e82f-8846-4362-a60a-92964285a31e",
"environment_json": {},
"memory": 256,
"instances": 1,
"disk_quota": 1024,
"state": "STARTED",
"version": "17175bdb-df93-4745-9a17-cf214fe05976",
"command": null,
"console": false,
"debug": null,
"staging_task_id": "5c74633a-25db-4adf-9eb8-09454a70be52",
"package_state": "STAGED",
"health_check_type": "port",
"health_check_timeout": null,
"health_check_http_endpoint": null,
"staging_failed_reason": null,
"staging_failed_description": null,
"diego": true,
"docker_image": null,
"package_updated_at": "2018-04-09T21:23:27Z",
"detected_start_command": "./vendor/initial_startup.rb",
"enable_ssh": true,
"ports": null
}
]
}
and getting the following values using
cat test.json | jq -r '.apps[].routes[].host, .apps[].state, .apps[].package_updated_at' which produces the following output
nodered-test
NodeRedTestApp
STARTED
STARTED
2018-04-10T17:32:06Z
2018-04-09T21:23:27Z
How can I get the output as
nodered-test STARTED 2018-04-10T17:32:06Z
NodeRedTestApp STARTED 2018-04-09T21:23:27Z
So that I can assign it to a bash script array.

jq solution:
jq -r '.apps[] | [.routes[].host, .state, .package_updated_at] | join(" ")' test.json
The output:
nodered-test STARTED 2018-04-10T17:32:06Z
NodeRedTestApp STARTED 2018-04-09T21:23:27Z

Related

How to flatten JSON with multiple nested objects in R

my sample data looks like this:
[
{
"conversationId": "string",
"companyId": "string",
"conversationChannels": [
"string"
],
"messageGroupName": "string",
"userProfile": {
"id": "string",
"firstName": "string",
"lastName": "string",
"whatsAppAccount": {
"id": "string",
"phone_number": "string",
"name": "string",
"locale": "string",
"instanceId": "string",
"is_group": true,
"is_twilio": false
},
"customFields": [ {
"companyDefinedFieldId": "string",
"value": "string"
}],
"contactLists": [],
"createdAt": "string",
"updatedAt": "string",
"lastContact": "string",
"lastContactFromCustomers": "string",
"isSandbox": false
},
"status": "string",
"assignee": {
"userInfo": {
"id": "string",
"firstName": "string",
"lastName": "string",
"displayName": "string",
"userName": "string",
"email": "string",
"phoneNumber": "string",
"emailConfirmed": true,
"createdAt": "string"
},
"roleType": "string",
"name": "string",
"locale": "string",
"timeZoneInfoId": "string",
"position": "string",
"status": "string",
"isAcceptedInvitation": true,
"isShowName": true,
"message": "string"
},
"additionalAssignees": [
{
"assignee": {
"userInfo": {
"id": "string",
"firstName": "string",
"lastName": "string",
"displayName": "string",
"userName": "string",
"email": "string",
"phoneNumber": "string",
"emailConfirmed": true,
"createdAt": "string"
},
"roleType": "string",
"name": "string",
"locale": "string",
"timeZoneInfoId": "string",
"position": "string",
"status": "string",
"isAcceptedInvitation": true,
"isShowName": true,
"message": "string"
}
}
],
where there are multiple levels of nested objects. I'm seeking to transform the data into flattened datafram to work on some data analysis. Here is my R code:
raw_convo_list <- GET(URL)
rawToChar(raw_convo_list$content)
df1<-data.frame(fromJSON(rawToChar(raw_convo_list$content), flatten = TRUE))
flatten(df1, recursive = TRUE)
However, the result has only one level of objects flattened. What can I do to split the rest out? Thank you.
I have tried using recursive flattenning, but the nested data were all put together with comma separated. My expected output was to have all fields of data separated out and parsed into relational database.

Change Text Link to Button

I am building a new site on the Empire Shopify theme and I am trying to change a text link into a button on the dynamic featured product section.
So changing this:
Featured product with text
Into this:
Call to action the button
Can anyone advise on the best way to do this please?
Here is the section code:
{% assign product = all_products[section.settings.product] %}
{% assign onboarding = false %}
{% if product.empty? %}
{% assign onboarding = true %}
{% endif %}
<script
type="application/json"
data-section-type="dynamic-featured-product"
data-section-id="{{ section.id }}"
data-section-data
>
{
"settings": {
"cart_redirection": {{ settings.enable_cart_redirection | json }},
"money_format": {{ shop.money_format | strip_html | json }},
"gallery_video_autoplay": {{ section.settings.gallery_video_autoplay | json }},
"gallery_video_looping": {{ section.settings.gallery_video_looping | json }},
"gallery_thumbnail_position": {{ section.settings.gallery_thumbnail_position | json }},
"gallery_hover_zoom": {{ section.settings.gallery_hover_zoom | json }},
"gallery_click_to_zoom": "disabled",
"swatches_enable": {{ settings.swatches_enable | json }},
"sold_out_options": {{ settings.sold_out_options | json }},
"select_first_available_variant": {{ settings.select_first_available_variant | json }}
},
"context": {
"select_variant": {{ 'product.general.select_variant' | t | json }},
"product_available": {{ 'product.buttons.add_to_cart' | t | json }},
"product_sold_out": {{ 'product.buttons.sold_out' | t | json }},
"product_unavailable": {{ 'product.buttons.unavailable' | t | json }},
"product_preorder": {{ 'product.buttons.pre_order' | t | json }}
},
"product": {% unless onboarding %}{{ product | json }}{% else %}false{% endunless} %}
}
</script>
<script type="application/pxs-animation-mapping+json">
{
"blocks": [".product-main"],
"elements": [
".product-details",
"[data-product-form-area]"
]
}
</script>
<section class="featured-product--container home-section--content" data-product-wrapper>
<div class="featured-product--inner">
{%
render 'product',
product: product,
is_product_modal: false,
is_featured_product: true,
onboarding: onboarding,
show_dynamic_checkout_button: settings.show_dynamic_checkout_button,
select_first_available_variant: settings.select_first_available_variant,
gallery_aspect_ratio: section.settings.gallery_aspect_ratio,
gallery_thumbnail_position: section.settings.gallery_thumbnail_position,
gallery_image_crop: section.settings.gallery_image_crop,
gallery_click_to_zoom: 'disabled',
gallery_hover_zoom: section.settings.gallery_hover_zoom
%}
</div>
</section>
{% schema %}
{
"name": "t:sections.featured_product.name",
"class": "featured-product--section",
"settings": [
{
"id": "product",
"type": "product",
"label": "t:sections.featured_product.product.label"
},
{
"type": "header",
"content": "t:sections.product.header_1.content"
},
{
"type": "paragraph",
"content": "t:sections.product.paragraph_1.content"
},
{
"type": "select",
"id": "gallery_aspect_ratio",
"label": "t:sections.product.gallery_aspect_ratio.label",
"options": [
{
"value": "natural",
"label": "t:sections.product.gallery_aspect_ratio.option_1"
},
{
"value": "short",
"label": "t:sections.product.gallery_aspect_ratio.option_2"
},
{
"value": "square",
"label": "t:sections.product.gallery_aspect_ratio.option_3"
},
{
"value": "tall",
"label": "t:sections.product.gallery_aspect_ratio.option_4"
}
],
"default": "natural"
},
{
"type": "checkbox",
"id": "gallery_image_crop",
"label": "t:sections.product.gallery_image_crop.label",
"info": "t:sections.product.gallery_image_crop.info",
"default": false
},
{
"id": "gallery_thumbnail_position",
"type": "select",
"label": "t:sections.product.gallery_thumbnail_position.label",
"info": "t:sections.product.gallery_thumbnail_position.info",
"options": [
{
"value": "below",
"label": "t:sections.product.gallery_thumbnail_position.option_1"
},
{
"value": "left",
"label": "t:sections.product.gallery_thumbnail_position.option_2"
}
],
"default": "below"
},
{
"type": "checkbox",
"id": "gallery_video_autoplay",
"label": "t:sections.product.gallery_video_autoplay.label",
"default": true
},
{
"type": "checkbox",
"id": "gallery_video_looping",
"label": "t:sections.product.gallery_video_looping.label",
"default": true
},
{
"id": "gallery_hover_zoom",
"type": "select",
"label": "t:sections.product.gallery_hover_zoom.label",
"options": [
{
"value": "disabled",
"label": "t:sections.product.gallery_hover_zoom.option_1"
},
{
"value": "replace",
"label": "t:sections.product.gallery_hover_zoom.option_2"
}
],
"info": "t:sections.product.gallery_hover_zoom.info",
"default": "disabled"
},
{
"type": "paragraph",
"content": "t:sections.product.paragraph_2.content"
}
],
"blocks": [
{
"type": "#app"
},
{
"type": "collapsible-tab",
"name": "t:sections.product.blocks.collapsible_tab.name",
"settings": [
{
"type": "text",
"id": "collapsible_tab_heading",
"label": "t:sections.product.blocks.collapsible_tab.collapsible_tab_heading.label",
"default": "Collapsible tab"
},
{
"type": "richtext",
"id": "collapsible_tab_text",
"label": "t:sections.product.blocks.collapsible_tab.collapsible_tab_text.label",
"default": "<p>Use this text to share information about your product.</p>"
}
]
},
{
"type": "custom-liquid",
"name": "t:sections.product.blocks.custom_liquid.name",
"limit": 1,
"settings": [
{
"type": "liquid",
"id": "custom_liquid",
"label": "t:sections.product.blocks.custom_liquid.custom_liquid.label",
"info": "t:sections.product.blocks.custom_liquid.custom_liquid.info"
}
]
},
{
"type": "description",
"name": "t:sections.product.blocks.description.name",
"limit": 1
},
{
"type": "form",
"name": "t:sections.product.blocks.form.name",
"limit": 1,
"settings": [
{
"type": "paragraph",
"content": "t:sections.product.blocks.form.paragraph_1.content"
},
{
"type": "header",
"content": "t:sections.product.blocks.form.header_1.content"
},
{
"type": "checkbox",
"id": "enable_local_pickup",
"label": "t:sections.product.blocks.form.enable_local_pickup.label",
"info": "t:sections.product.blocks.form.enable_local_pickup.info",
"default": true
}
]
},
{
"type": "key_details",
"name": "t:sections.product.blocks.key_details.name",
"settings": [
{
"type": "select",
"id": "icon",
"label": "t:sections.product.blocks.key_details.icon.label",
"options": [
{
"value": "none",
"label": "t:sections.product.blocks.key_details.icon.option_1"
},
{
"value": "icon-award-trophy",
"label": "t:sections.product.blocks.key_details.icon.option_2"
},
{
"value": "icon-car",
"label": "t:sections.product.blocks.key_details.icon.option_3"
},
{
"value": "icon-cell-phone",
"label": "t:sections.product.blocks.key_details.icon.option_4"
},
{
"value": "icon-chat",
"label": "t:sections.product.blocks.key_details.icon.option_5"
},
{
"value": "icon-chat-alternate",
"label": "t:sections.product.blocks.key_details.icon.option_6"
},
{
"value": "icon-credit-card",
"label": "t:sections.product.blocks.key_details.icon.option_7"
},
{
"value": "icon-delivery",
"label": "t:sections.product.blocks.key_details.icon.option_8"
},
{
"value": "icon-delivery-cart",
"label": "t:sections.product.blocks.key_details.icon.option_9"
},
{
"value": "icon-delivery-door",
"label": "t:sections.product.blocks.key_details.icon.option_10"
},
{
"value": "icon-delivery-package",
"label": "t:sections.product.blocks.key_details.icon.option_11"
},
{
"value": "icon-email",
"label": "t:sections.product.blocks.key_details.icon.option_12"
},
{
"value": "icon-envelope",
"label": "t:sections.product.blocks.key_details.icon.option_13"
},
{
"value": "icon-gift-card",
"label": "t:sections.product.blocks.key_details.icon.option_14"
},
{
"value": "icon-heart",
"label": "t:sections.product.blocks.key_details.icon.option_15"
},
{
"value": "icon-information",
"label": "t:sections.product.blocks.key_details.icon.option_16"
},
{
"value": "icon-label-tag",
"label": "t:sections.product.blocks.key_details.icon.option_17"
},
{
"value": "icon-lock",
"label": "t:sections.product.blocks.key_details.icon.option_18"
},
{
"value": "icon-number-14",
"label": "t:sections.product.blocks.key_details.icon.option_19"
},
{
"value": "icon-number-24",
"label": "t:sections.product.blocks.key_details.icon.option_20"
},
{
"value": "icon-number-30",
"label": "t:sections.product.blocks.key_details.icon.option_21"
},
{
"value": "icon-people",
"label": "t:sections.product.blocks.key_details.icon.option_22"
},
{
"value": "icon-pin",
"label": "t:sections.product.blocks.key_details.icon.option_23"
},
{
"value": "icon-question-mark",
"label": "t:sections.product.blocks.key_details.icon.option_24"
},
{
"value": "icon-rating-five-star",
"label": "t:sections.product.blocks.key_details.icon.option_25"
},
{
"value": "icon-rating-star",
"label": "t:sections.product.blocks.key_details.icon.option_26"
},
{
"value": "icon-smile",
"label": "t:sections.product.blocks.key_details.icon.option_27"
},
{
"value": "icon-store",
"label": "t:sections.product.blocks.key_details.icon.option_28"
},
{
"value": "icon-tape-measure",
"label": "t:sections.product.blocks.key_details.icon.option_29"
},
{
"value": "icon-thumbs-up",
"label": "t:sections.product.blocks.key_details.icon.option_30"
},
{
"value": "icon-transfer",
"label": "t:sections.product.blocks.key_details.icon.option_31"
}
],
"default": "icon-delivery-package"
},
{
"type": "image_picker",
"id": "image",
"label": "t:sections.product.blocks.key_details.image.label",
"info": "t:sections.product.blocks.key_details.image.info"
},
{
"type": "text",
"id": "title",
"label": "t:sections.product.blocks.key_details.title.label",
"default": "Delivery time"
},
{
"type": "richtext",
"id": "text",
"label": "t:sections.product.blocks.key_details.text.label",
"default": "<p>Use this text to share information about your product and policies with your customers.</p>"
},
{
"type": "color",
"id": "text_color",
"label": "t:sections.product.blocks.key_details.text_color.label",
"default": "#1D1D1D"
},
{
"type": "color",
"id": "icon_color",
"label": "t:sections.product.blocks.key_details.icon_color.label",
"default": "#1D1D1D"
},
{
"type": "color",
"id": "background_color",
"label": "t:sections.product.blocks.key_details.background_color.label",
"default": "#f5f3ed"
}
]
},
{
"type": "inventory_status",
"name": "t:sections.product.blocks.inventory_status.name",
"limit": 1,
"settings": [
{
"type": "radio",
"id": "inventory_display",
"label": "t:sections.product.blocks.inventory_status.inventory_display.label",
"info": "t:sections.product.blocks.inventory_status.inventory_display.info",
"options": [
{
"value": "all_products",
"label": "t:sections.product.blocks.inventory_status.inventory_display.option_1"
},
{
"value": "low_stock_threshold",
"label": "t:sections.product.blocks.inventory_status.inventory_display.option_2"
},
{
"value": "low_stock_only",
"label": "t:sections.product.blocks.inventory_status.inventory_display.option_3"
},
{
"value": "hidden",
"label": "t:sections.product.blocks.inventory_status.inventory_display.option_4"
}
],
"default": "hidden"
},
{
"type": "checkbox",
"id": "inventory_transfer_notice",
"label": "t:sections.product.blocks.inventory_status.inventory_transfer_notice.label",
"info": "t:sections.product.blocks.inventory_status.inventory_transfer_notice.info",
"default": true
}
]
},
{
"type": "price",
"name": "t:sections.product.blocks.price.name",
"limit": 1
},
{
"type": "rating",
"name": "t:sections.product.blocks.product_rating.name",
"limit": 1,
"settings": [
{
"type": "paragraph",
"content": "t:sections.product.blocks.product_rating.paragraph_1.content"
}
]
},
{
"type": "share",
"name": "t:sections.product.blocks.share.name",
"limit": 1
},
{
"type": "tabs",
"name": "t:sections.product.blocks.tabs.name",
"limit": 1,
"settings": [
{
"type": "checkbox",
"id": "show_product_description",
"label": "t:sections.product.blocks.tabs.show_product_description.label",
"default": false
},
{
"type": "checkbox",
"id": "show_tabs_below_product_gallery",
"label": "t:sections.product.blocks.tabs.show_tabs_below_product_gallery.label",
"info": "t:sections.product.blocks.tabs.show_tabs_below_product_gallery.info",
"default": false
},
{
"type": "header",
"content": "t:sections.product.blocks.tabs.header_1.content"
},
{
"type": "text",
"id": "tab_heading_1",
"label": "t:sections.product.blocks.tabs.tab_heading_1.label",
"default": "Tab 1"
},
{
"type": "richtext",
"id": "tab_text_1",
"label": "t:sections.product.blocks.tabs.tab_text_1.label",
"default": "<p>Use this text to share information about your product.</p>"
},
{
"type": "header",
"content": "t:sections.product.blocks.tabs.header_2.content"
},
{
"type": "text",
"id": "tab_heading_2",
"label": "t:sections.product.blocks.tabs.tab_heading_2.label",
"default": "Tab 2"
},
{
"type": "richtext",
"id": "tab_text_2",
"label": "t:sections.product.blocks.tabs.tab_text_2.label",
"default": "<p>Use this text to share information about your product.</p>"
},
{
"type": "header",
"content": "t:sections.product.blocks.tabs.header_3.content"
},
{
"type": "text",
"id": "tab_heading_3",
"label": "t:sections.product.blocks.tabs.tab_heading_3.label",
"default": "Tab 3"
},
{
"type": "richtext",
"id": "tab_text_3",
"label": "t:sections.product.blocks.tabs.tab_text_3.label",
"default": "<p>Use this text to share information about your product.</p>"
}
]
},
{
"type": "sku",
"name": "t:sections.product.blocks.sku.name",
"limit": 1
},
{
"type": "text",
"name": "t:sections.product.blocks.text.name",
"settings": [
{
"type": "richtext",
"id": "text",
"label": "t:sections.product.blocks.text.text.label",
"default": "<p>Text block</p>"
}
]
},
{
"type": "title",
"name": "t:sections.product.blocks.title.name",
"limit": 1
},
{
"type": "vendor",
"name": "t:sections.product.blocks.vendor.name",
"limit": 1
},
{
"type": "view-product-link",
"name": "t:sections.featured_product.blocks.view_product_link.name",
"limit": 1,
"settings": [
{
"type": "text",
"id": "text",
"label": "t:sections.featured_product.blocks.view_product_link.text.label",
"default": "View full details"
}
]
}
],
"presets": [
{
"name": "t:sections.featured_product.presets.featured_product.name",
"category": "t:sections.featured_product.presets.featured_product.category",
"blocks": [
{
"type": "title"
},
{
"type": "price"
},
{
"type": "view-product-link"
}
]
}
]
}
{% endschema %}
It is just styling issue. You can customize that text link to be like a button using some CSS codes in your original section template file.
just for an example;
.btn_viewWallGuide {
padding: 30px 70px;
background-color: #F04F37;
border-radius: 6px;
color: white;
font-weight: 700;
font-size: 28px;
font-family: system-ui;
text-decoration: none;
}
<a class="btn_viewWallGuide" href="{{ section.settings.your_schema_link_id }}">View Wall Guide</a>

ELASTICSEARCH - Aggregations not working on string field

Elastic search extraction query is returning expected results in hints section of output but aggregation on field returning empty response
output without aggregation
{
"_shards": {
"total": 45,
"failed": 0,
"successful": 45,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "logstash-wander-2022.08.17",
"_type": "fluentd",
"_source": {
"outboundResponseStatus": "SERVICE_UNAVAILABLE"
},
"_id": "Y2NlNjkzZmEtNjZlMi00NWY4LTllNWUtOWZmNWRhMjRkMzA3",
"sort": [
1660695790244
],
"_score": null
},
{
"_index": "logstash-wander-2022.08.17",
"_type": "fluentd",
"_source": {
"outboundResponseStatus": "CONFLICT"
},
"_id": "OWNmZTFiOWEtYWQ2Mi00OGViLWFmY2EtMGQ4ZDg1NzRiYWNk",
"sort": [
1660695781810
],
"_score": null
}
],
"total": 25,
"max_score": null
},
"took": 506,
"timed_out": false
}
But adding below aggregation along with query returning empty response
"aggregations": {
"outboundResponseStatus": {
"significant_terms": {
"field": "outboundResponseStatus",
"keyed": true
}
}
}
Below is the query
{
"size": 500,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "search string",
"default_field": "*",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"analyze_wildcard": true,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1
}
},
{
"match_phrase": {
"message": {
"query": "search string",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
},
{
"range": {
"#timestamp": {
"from": "now-10m",
"to": "now",
"include_lower": true,
"include_upper": true,
"format": "epoch_millis",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"version": true,
"_source": {
"includes": [
"outboundResponseStatus",
"outboundUri",
"message"
],
"excludes": []
},
"stored_fields": "*",
"script_fields": {},
"sort": [
{
"#timestamp": {
"order": "desc",
"unmapped_type": "boolean"
}
}
]
}
How to get aggregations based on field in hints results?

Find sequence with single pickup and multiple dropoffs here-api. Next pickup must happen after existing delivery is completed

I got a scenario of completing 3 deliveries.
Delivery 1 - 1 Pickup (P1) and 3 Drop offs (D11,D12,D13).
Delivery 2 - 1 Pickup (P2) and 2 Drop offs (D21,D22).
Delivery 3 - 1 Pickup (P3) and 3 Drop offs (D31,D32,D33).
it should provide a route in a way that next pickup should happen after existing delivery is completed.
e.g. if we consider P2 as first point then P1 or P3 must come after D21 and D22. Here sequence of Drop offs can be anything.
The HERE Tour Planning API should be able to solve your problem. Here you can define your jobs with pickups and deliveries, and the API provides you an optimized tour.
You can also define properties of your fleet, to take into account.
https://developer.here.com/documentation/tour-planning/dev_guide/index.html
Example request:
{
"id": "7f3423c2-784a-4983-b472-e14107d5a54a",
"plan": {
"jobs": [
{
"id": "7f3423c2-784a-4983-b472-e14107d5a54a",
"places": {
"pickup": {
"times": [
[
"2019-07-04T08:00:00Z",
"2019-07-04T10:00:00Z"
],
[
"2019-07-04T16:00:00Z",
"2019-07-04T18:00:00Z"
]
],
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"duration": 180,
"tag": {
"tag": "some tag"
}
},
"delivery": {
"times": [
[
"2019-07-04T08:00:00Z",
"2019-07-04T10:00:00Z"
],
[
"2019-07-04T16:00:00Z",
"2019-07-04T18:00:00Z"
]
],
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"duration": 180,
"tag": {
"tag": "some tag"
}
}
},
"demand": [
10,
5
],
"skills": [
"fridge"
]
}
],
"relations": [
{
"type": "sequence",
"jobs": [
"departure",
"job1",
"break",
"job2"
],
"vehicleId": "7f3423c2-784a-4983-b472-e14107d5a54a"
}
]
},
"fleet": {
"types": [
{
"id": "7f3423c2-784a-4983-b472-e14107d5a54a",
"profile": {
"tag": "big truck"
},
"costs": {
"fixed": 22,
"distance": 0.0001,
"time": 0.0048
},
"shifts": [
{
"start": {
"time": "2019-07-04T00:00:00Z",
"location": {
"lat": 52.53088,
"lng": 13.38471
}
},
"end": {
"time": "2019-07-04T00:00:00Z",
"location": {
"lat": 52.53088,
"lng": 13.38471
}
},
"breaks": [
{
"times": [
[
"2019-07-04T08:00:00Z",
"2019-07-04T10:00:00Z"
],
[
"2019-07-04T16:00:00Z",
"2019-07-04T18:00:00Z"
]
],
"duration": 180,
"location": {
"lat": 52.53088,
"lng": 13.38471
}
}
]
}
],
"capacity": [
10,
5
],
"skills": [
"fridge"
],
"limits": {
"maxDistance": 20000,
"shiftTime": 21600
},
"amount": 1
}
],
"profiles": [
{
"name": {
"tag": "big truck"
},
"departureTime": "2019-07-04T00:00:00Z",
"avoidRoutes": {
"features": [
"tollRoad"
]
},
"type": "car"
}
]
},
"configuration": {
"optimizations": {
"traffic": "liveOrHistorical",
"waitingTime": {
"reduce": true,
"bufferTime": 15
}
}
}
}
Response:
{
"problemId": "7f3423c2-784a-4983-b472-e14107d5a54a",
"statistic": {
"cost": 1024,
"distance": 32000,
"duration": 180,
"times": {
"driving": 3600,
"serving": 600,
"waiting": 180,
"break": 1200
}
},
"tours": [
{
"vehicleId": "7f3423c2-784a-4983-b472-e14107d5a54a",
"typeId": "7f3423c2-784a-4983-b472-e14107d5a54a",
"stops": [
{
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"time": {
"arrival": "2019-07-04T00:00:00Z",
"departure": "2019-07-04T00:00:00Z"
},
"load": [
10,
5
],
"activities": [
{
"jobId": "7f3423c2-784a-4983-b472-e14107d5a54a",
"jobTag": {
"tag": "some tag"
},
"type": "delivery",
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"time": {
"start": "2019-07-04T00:00:00Z",
"end": "2019-07-04T00:00:00Z"
}
}
]
}
],
"statistic": {
"cost": 1024,
"distance": 32000,
"duration": 180,
"times": {
"driving": 3600,
"serving": 600,
"waiting": 180,
"break": 1200
}
}
}
],
"unassigned": [
{
"jobId": "7f3423c2-784a-4983-b472-e14107d5a54a",
"reasons": [
{
"code": 1,
"description": "cannot serve required skill"
}
]
}
]
}

How do I create custom output object in Kusto

I have array like below as one of the properties for my object. I'd like to extract certain fields and return it still as array in output. For example I want only name and storageAccountType to be returned like below
Desired Output
[
{
"name": "Data",
"storageAccountType": "Standard_LRS"
},
{
"name": "Disk2",
"storageAccountType": "Standard_LRS"
}
]
Input Array
[
{
"name": "Data",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 0
},
{
"name": "Disk2",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 1
}
]
here's a direction you could follow (which assumes you actually needs to get back arrays and not to have each element in the array in its own row. if the latter is good, remove the rows with the comments (// *)
datatable(some_value:string, d:dynamic) // just a sample data set with 2 records
[
"hello", dynamic([
{
"name": "Data",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 0
},
{
"name": "Disk2",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 1
}
]), "world", dynamic([
{
"name": "Data3",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 0
},
{
"name": "Disk23",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 1
}
])
]
// --> answer starts here <--
| extend r = rand() // *
| mv-apply d on (
project d = pack("name", d.name, "storageAccountType", d.managedDisk.storageAccountType)
)
| summarize d = make_list(d) by r, some_value // *
| project-away r // *

Resources