Why isn't the sequencer repeating the AutoPage? - alexa

Got Actual:
Text1 --> Text2 --> Text3
Expected: (wanted it to repeat)
Text1 --> Text2 --> Text3 --> Text1 --> Text2 --> Text3 --> Text1 --> ...
Apl Code: https://apl.ninja/document/Borghild/why-sequencer-not-repeating-6sts
{
"type": "APL",
"version": "1.8",
"settings": {},
"theme": "dark",
"import": [
{
"name": "alexa-layouts",
"version": "1.5.0"
}
],
"mainTemplate": {
"parameters": [
"payload"
],
"items": [
{
"type": "Pager",
"id": "myPager",
"items": [
{
"type": "Text",
"text": "Text1"
},
{
"type": "Text",
"text": "Text2"
},
{
"type": "Text",
"text": "Text3"
}
],
"onMount": [
{
"type": "Sequential",
"sequencer": "mySequencer",
"repeatCount": 99999,
"commands": [
{
"type": "AutoPage",
"componentId": "myPager",
"duration": 500
}
]
}
]
}
]
}
}

Found the solution in addition to autoPage I need to add also setPage just after autoPage like this, and now it repeats.
"commands": [
{
"type": "AutoPage",
"componentId": "myPager",
"duration": 500
},
{
"type": "SetPage",
"componentId": "myPager",
"value": 0
}
]

Related

Vega Chloropleth Map Visualisation

For some reason vega is reading my data as 0 when the numbers range from 1-234.
I am attempting to show a visualisation of a chloropleth map of crypto-ownership by country.
The countries have been ranked 1-234 and that is meant to show on the tooltip however, this is being shown as 0 on the tooltip. How do I fix this.
Here is my code:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"title":{
"text": "Crypto Ownership Worldwide",
"subtitle": "Source: FILL",
"anchor": "start"
},
"width":500,
"height":400,
"data": {
"url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/custom.geo%20(3).json",
"format":{"property": "features"}
},
"projection":{"type": "mercator"},
"transform": [
{
"lookup":"properties.name",
"from":{
"key": "Country",
"fields": ["Rank"],
"data":{
"url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/datarank.csv",
"format":{"type":"csv"}
}
}
}
],
"mark":{
"type": "geoshape",
"fill":"lightgray",
"stroke":"black",
"strokeWidth":0.5
},
"encoding": {
"color": {
"field": "Rank",
"type": "quantitative",
"scale": {
"domain":[234,1],
"scheme": "oranges"
}
},
"tooltip":[
{"field":"properties.name", "title":"Country"},
{"field":"Rank","type":"quantitative","title":"Number of Crypto Owners","format":".2f"}
]
},
"config": {"mark": {"invalid": null}
}
}
Your lookup was failing. You need a lower case "c" on country.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"title": {
"text": "Crypto Ownership Worldwide",
"subtitle": "Source: FILL",
"anchor": "start"
},
"width": 500,
"height": 400,
"data": {
"url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/custom.geo%20(3).json",
"format": {"property": "features"}
},
"projection": {"type": "mercator"},
"transform": [
{
"lookup": "properties.name",
"from": {
"key": "country",
"fields": ["Rank"],
"data": {
"url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/datarank.csv",
"format": {"type": "csv"}
} }
}
],
"mark": {
"type": "geoshape",
"fill": "lightgray",
"stroke": "black",
"strokeWidth": 0.5
},
"encoding": {
"color": {
"field": "Rank",
"type": "quantitative",
"scale": {"domain": [234, 1], "scheme": "oranges"}
},
"tooltip": [
{"field": "properties.name", "title": "Country"},
{
"field": "Rank",
"type": "quantitative",
"title": "Number of Crypto Owners",
"format": ".2f"
}
]
},
"config": {"mark": {"invalid": null}}
}

What is the correct way to integrate audio & visual response using Alexa APL?

I have an Alexa audio and visual response that is returned on the first launch of an Alexa App. I use a transformer to embed the APLA document. Up until recently this was working.
This is the APL document:
{
"type": "APL",
"version": "2022.1",
"license": "Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: LicenseRef-.amazon.com.-AmznSL-1.0\nLicensed under the Amazon Software License http://aws.amazon.com/asl/",
"theme": "dark",
"import": [
{
"name": "alexa-layouts",
"version": "1.5.0"
}
],
"onMount": [
{
"type": "SpeakItem",
"componentId": "initialAPLAcomponent"
}
],
"resources": [
{
"description": "Default resource definitions for Video template",
"dimensions": {
"videoHeight": "55%",
"videoPaddingTop": "80dp",
"videoWidth": "70vw",
"videoControlPaddingBottom": "0dp",
"videoSliderPaddingBottom": "80dp"
}
},
{
"when": "${#viewportProfile == #hubLandscapeLarge}",
"dimensions": {
"videoHeight": "60%",
"videoPaddingTop": "110dp",
"videoControlPaddingBottom": "10dp",
"videoSliderPaddingBottom": "90dp"
}
},
{
"when": "${#viewportProfile == #hubLandscapeSmall || #viewportProfile == #hubRoundSmall}",
"dimensions": {
"videoHeight": "50%",
"videoPaddingTop": "70dp",
"videoControlPaddingBottom": "15dp"
}
}
],
"commands": {
"ToggleVideoOverlay": {
"parameters": [
"componentId",
"show"
],
"commands": [
{
"type": "Sequential",
"commands": [
{
"when": "${show}",
"type": "SetValue",
"componentId": "${componentId}",
"property": "display",
"value": "normal"
},
{
"type": "AnimateItem",
"easing": "ease-in-out",
"duration": 1000,
"componentId": "${componentId}",
"value": [
{
"property": "opacity",
"from": "${show ? 0 : 0.5}",
"to": "${show ? 0.5 : 0}"
}
]
},
{
"when": "${!show}",
"type": "SetValue",
"componentId": "${componentId}",
"property": "display",
"value": "none"
}
]
}
]
},
"ToggleVideoControls": {
"parameters": [
"componentId",
"direction",
"show"
],
"commands": [
{
"type": "Sequential",
"commands": [
{
"type": "AnimateItem",
"easing": "ease-in-out",
"duration": 1000,
"componentId": "${componentId}",
"value": [
{
"property": "opacity",
"from": "${show ? 0 : 1}",
"to": "${show ? 1 : 0}"
},
{
"property": "transform",
"from": [
{
"translateY": "${!show ? 0 : (direction == 'down' ? -50 : 50)}"
}
],
"to": [
{
"translateY": "${show ? 0 : (direction == 'down' ? 50 : -50)}"
}
]
}
]
},
{
"type": "SetValue",
"property": "videoControlsDisplay",
"value": "${show ? true : false}"
}
]
}
]
}
},
"layouts": {
"VideoPlayer": {
"parameters": [
{
"name": "backgroundImageSource",
"description": "URL for the background image source in fullscreen.",
"type": "string"
},
{
"name": "displayFullscreen",
"description": "Select to display video in fullscreen. Video controls will be displayed on tap.",
"type": "boolean",
"default": false
},
{
"name": "headerTitle",
"description": "Title text to render in the header.",
"type": "string"
},
{
"name": "headerSubtitle",
"description": "Subtitle Text to render in the header.",
"type": "string"
},
{
"name": "headerAttributionImage",
"description": "URL for attribution image or logo source (PNG/vector).",
"type": "string"
},
{
"name": "videoControlType",
"description": "The type of video control to use. Default is skip (foward and backwards).",
"type": "string",
"default": "skip"
},
{
"name": "videoSources",
"description": "Video single source or an array of sources. Videos will be in a playlist if multiple sources are provided.",
"type": "any"
},
{
"name": "sliderType",
"description": "Determinate for full control of the slider with transport control. Indeterminate is an ambient progress bar with animation.",
"type": "string",
"default": "determinate"
},
{
"name": "autoplay",
"type": "boolean",
"default": true,
"description": "Determines the starting state of the play/pause icon. This should match the autoplay state of the media playing component. Defaults to false. "
}
],
"item": {
"type": "Container",
"height": "100vh",
"width": "100vw",
"bind": [
{
"name": "sliderThumbPosition",
"type": "number",
"value": 0
},
{
"name": "sliderActive",
"type": "boolean",
"value": false
},
{
"name": "videoProgressValue",
"type": "number",
"value": 0
},
{
"name": "videoTotalValue",
"type": "number",
"value": 0
},
{
"name": "videoControlsDisplay",
"type": "boolean",
"value": false
}
],
"handleTick": [
{
"when": "${!sliderActive && displayFullscreen && videoControlsDisplay}",
"minimumDelay": 5000,
"description": "For video fullscreen view, hide video controls after 5 seconds of inactivity",
"commands": [
{
"type": "Parallel",
"sequencer": "ToggleVideoControlsSequencer",
"commands": [
{
"type": "ToggleVideoOverlay",
"componentId": "videoOverlay",
"show": false
},
{
"type": "ToggleVideoControls",
"componentId": "videoHeader",
"direction": "up",
"show": false
},
{
"type": "ToggleVideoControls",
"componentId": "videoControls",
"direction": "down",
"show": false
}
]
}
]
}
],
"items": [
{
"type": "AlexaBackground",
"id": "AlexaBackground",
"backgroundColor": "${backgroundColor}",
"backgroundImageSource": "${backgroundImageSource}"
},
{
"description": "Video container",
"type": "Container",
"height": "100%",
"width": "100%",
"position": "absolute",
"item": {
"type": "TouchWrapper",
"height": "100%",
"width": "100%",
"description": "Outer touch wrapper that brings up the controls",
"onPress": [
{
"when": "${displayFullscreen}",
"type": "Parallel",
"sequencer": "ToggleVideoControlsSequencer",
"commands": [
{
"type": "ToggleVideoOverlay",
"componentId": "videoOverlay",
"show": true
},
{
"type": "ToggleVideoControls",
"componentId": "videoHeader",
"direction": "down",
"show": true
},
{
"type": "ToggleVideoControls",
"componentId": "videoControls",
"direction": "up",
"show": true
}
]
}
],
"item": {
"type": "Container",
"height": "100%",
"width": "100%",
"alignItems": "center",
"item": {
"type": "Video",
"height": "${displayFullscreen ? '100%' : #videoHeight}",
"width": "${displayFullscreen ? '100%' : #videoWidth}",
"scale": "best-fill",
"autoplay": true,
"audioTrack": "foreground",
"id": "videoPlayerId",
"source": "${videoSources}",
"position": "absolute",
"top": "${displayFullscreen ? '0' : #videoPaddingTop}",
"onPlay": [
{
"type": "SetValue",
"property": "videoTotalValue",
"value": "${event.duration}"
},
{
"type": "SpeakItem",
"componentId": "initialAPLAcomponent"
}
],
"onTrackUpdate": [
{
"type": "SetValue",
"property": "videoTotalValue",
"value": "${event.duration}"
}
],
"onTimeUpdate": [
{
"type": "SetValue",
"property": "videoProgressValue",
"value": "${event.currentTime}"
},
{
"type": "SetValue",
"componentId": "slider",
"property": "progressValue",
"value": "${videoProgressValue}"
},
{
"type": "SetValue",
"property": "videoTotalValue",
"value": "${event.duration}"
}
],
"onTrackReady": [
{
"type": "SetValue",
"property": "videoTotalValue",
"value": "${event.duration}"
}
],
"onTrackFail": [
{
"type": "SetValue",
"property": "videoTotalValue",
"value": "0"
}
]
}
}
}
},
{
"description": "Header, slider, and controls container",
"type": "Container",
"height": "100%",
"width": "100%",
"items": [
{
"description": "Oveylay background for Video Controls",
"when": "${displayFullscreen}",
"type": "Frame",
"id": "videoOverlay",
"height": "100%",
"width": "100%",
"backgroundColor": "${viewport.theme == 'light' ? '#colorWhite' : '#colorBlack'}",
"position": "absolute",
"display": "none",
"opacity": 0
},
{
"when": "${#viewportProfileCategory != #hubRound}",
"type": "AlexaHeader",
"id": "videoHeader",
"opacity": "${displayFullscreen ? 0 : 1}",
"layoutDirection": "${environment.layoutDirection}",
"headerAttributionImage": "${headerAttributionImage}",
"headerTitle": "${headerTitle} ",
"headerSubtitle": "${headerSubtitle} ",
"headerAttributionPrimacy": true,
"width": "100%",
"theme": "${viewport.theme}"
},
{
"description": "Slider and controls",
"type": "Container",
"id": "videoControls",
"opacity": "${displayFullscreen ? 0 : 1}",
"width": "100%",
"position": "absolute",
"bottom": 0,
"items": [
{
"when": "${sliderType != 'indeterminate'}",
"type": "Container",
"alignItems": "center",
"item": [
{
"type": "AlexaSlider",
"id": "slider",
"progressValue": "${videoProgressValue}",
"totalValue": "${videoTotalValue}",
"positionPropertyName": "sliderThumbPosition",
"metadataDisplayed": true,
"metadataPosition": "above_right",
"width": "${#videoWidth + 5vw}",
"paddingBottom": "#videoSliderPaddingBottom",
"theme": "${viewport.theme}",
"onUpCommand": [
{
"type": "ControlMedia",
"componentId": "videoPlayerId",
"command": "seek",
"value": "${sliderThumbPosition - videoProgressValue}"
},
{
"delay": "1000",
"type": "SetValue",
"sequencer": "ToggleVideoControlsSequencer",
"property": "sliderActive",
"value": false
}
],
"onMoveCommand": [
{
"type": "SetValue",
"property": "sliderActive",
"value": true
}
],
"onDownCommand": [
{
"type": "SetValue",
"property": "sliderActive",
"value": true
}
]
},
{
"type": "AlexaTransportControls",
"mediaComponentId": "videoPlayerId",
"playPauseToggleButtonId": "playPauseToggleButtonId",
"primaryControlSize": "70dp",
"secondaryControls": "${videoControlType}",
"secondaryControlSize": "60dp",
"autoplay": true,
"position": "absolute",
"bottom": "#videoControlPaddingBottom",
"theme": "${viewport.theme}"
}
]
},
{
"when": "${sliderType == 'indeterminate'}",
"type": "Container",
"alignItems": "center",
"item": [
{
"type": "AlexaProgressBar",
"progressBarType": "indeterminate",
"width": "#videoWidth",
"paddingBottom": "#videoSliderPaddingBottom",
"theme": "${viewport.theme}"
}
]
}
]
}
]
}
]
}
},
"AudioTransform": {
"parameters": [
{
"name": "audioSource",
"type": "string"
}
],
"items": [
{
"type": "Container",
"items": [
{
"type": "Text",
"id": "initialAPLAcomponent",
"speech": "${audioSource}"
}
]
}
]
}
},
"mainTemplate": {
"parameters": [
"payload"
],
"items": [
{
"type": "VideoPlayer",
"backgroundImageSource": "${payload.videoPlayerTemplateData.properties.backgroundImage}",
"displayFullscreen": "${payload.videoPlayerTemplateData.properties.displayFullscreen}",
"headerAttributionImage": "${payload.videoPlayerTemplateData.properties.logoUrl}",
"headerTitle": "${payload.videoPlayerTemplateData.properties.headerTitle}",
"headerSubtitle": "${payload.videoPlayerTemplateData.properties.headerSubtitle}",
"videoControlType": "${payload.videoPlayerTemplateData.properties.videoControlType}",
"videoSources": "${payload.videoPlayerTemplateData.properties.videoSources}",
"sliderType": "${payload.videoPlayerTemplateData.properties.sliderType}"
},
{
"type": "AudioTransform",
"audioSource": "${payload.videoPlayerTemplateData.properties.outputAPLA.url}"
}
]
}
}
This is the datasource:
{
"videoPlayerTemplateData": {
"type": "object",
"properties": {
"backgroundImage": "",
"displayFullscreen": true,
"headerTitle": "",
"headerSubtitle": "",
"logoUrl": "https://my.png",
"videoControlType": "jump10",
"videoSources": [
"https://my.mp4"
],
"sliderType": "determinate"
},
"transformers": [
{
"template": "intialAPLA",
"outputName": "outputAPLA",
"transformer": "aplAudioToSpeech"
}
]
}
}
and this is the APLA source:
{
"intialAPLA": {
"type": "APLA",
"version": "0.91",
"mainTemplate": {
"parameters": [
"payload"
],
"item": [
{
"type": "Mixer",
"items": [
{
"type": "Sequencer",
"items": [
{
"type": "Audio",
"description": "sound from bank",
"source": "my.sound"
},
{
"type": "Speech",
"content": "myspeech "
}
]
},
{
"type": "Audio",
"source": "https://my.mp3",
"duration": "trimToParent",
"filter": [
{
"type": "Volume",
"amount": "50%"
},
{
"type": "FadeOut",
"duration": 2000
}
]
}
]
}
]
}
}
}
If I remove the video item from the main template the audio plays, so I know this is not an issue with the transformer. I've tried setting the speech attrbute of the video, in layouts, to be the transformer binding, and playing that onMount, but that doesn't work either.
It seems I can only play video or the audio, not both. This worked previously so I'm not sure what's changed.
Are you able to see why I can't return the video with the audio embedded?

Removing and printing name/value pair from json using jolt

I want to remove a name/value pair from inside a json array and print it outside. I started by trying this and then expanding the whole request to be a json array. The solution mentioned above does not seem to be working.
Input :
[
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
},
{
"name": "Details",
"value": {
"createdDate": "today",
"description": "offer",
"id": null
}
}
],
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
},
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
},
{
"name": "Details",
"value": {
"createdDate": "today",
"description": "offer",
"id": null
}
}
],
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
}
]
Desired Output :
[
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
}
],
"Details": {
"createdDate": "today",
"description": "offer",
"id": null
},
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
},
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
}
],
"Details": {
"createdDate": "today",
"description": "offer",
"id": null
},
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
}
]
Current Jolt spec:
[
{
"operation": "shift",
"spec": {
"*": "[&]",
"attrs": {
"*": {
"name": {
"*": { "#2": "&4" },
"Details": {
"#(2,value)": "&1"
}
}
}
}
}
}
]
I can't seem to figure out how the jolt spec would change in case of the array
So far so good, just need to combine the attributes at a common node. To do this, I've used the identifiers [&1] and [&5] in order to reach the level of the outermost index within the tree such as
[
{
"operation": "shift",
"spec": {
"*": {
"*": "[&1].&",
"attrs": {
"*": {
"name": {
"*": {
"#2": "[&5].&4"
},
"Details": {
"#(2,value)": "[&5].&1"
}
}
}
}
}
}
}
]

LogicApp - How to check if collection is empty

What I would like to do it if there is addOn array, I would like to append the word "xxx" to the end of the name.
Schema applied to message.
{
"properties": {
"appointment": {
"properties": {
"id": {
"type": "integer"
},
"lines": {
"items": {
"properties": {
"addOn": {
"items": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
],
"type": "object"
},
"type": "array"
},
"id": {
"type": "integer"
},
"price": {
"type": "integer"
}
},
"required": [
"id",
"price"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"messageId": {
"type": "string"
}
},
"type": "object"
}
Message 1
{
"messageId": "11",
"appointment": {
"id": 22,
"lines": [
{
"id": 33,
"price": 125.0,
"addOn": [
{
"id": 44,
"name": "test"
}
]
}
]
}
}
Message 2
{
"messageId": "11",
"appointment": {
"id": 22,
"lines": [
{
"id": 33,
"price": 125.0
}
]
}
}
Message 1 works fine but whenever I try and use length or Parse Array I get a message that addOn is null.
How can I put a proper Condition express to not get any errors or do nothing when there is no addOn array.
Logic App.
Message1 - Okay
Message2 - Error
Code View.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"For_each_2": {
"actions": {
"Condition_3": {
"actions": {},
"expression": {
"and": [
{
"equals": [
"#empty(items('For_each_2'))",
"True"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"foreach": "#items('For_each')['addOn']",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "#body('Parse_JSON')?['appointment']?['lines']",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Parse_JSON": {
"inputs": {
"content": "#triggerBody()",
"schema": {
"properties": {
"appointment": {
"properties": {
"id": {
"type": "integer"
},
"lines": {
"items": {
"properties": {
"addOn": {
"items": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
],
"type": "object"
},
"type": "array"
},
"id": {
"type": "integer"
},
"price": {
"type": "integer"
}
},
"required": [
"id",
"price"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"messageId": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"appointment": {
"properties": {
"id": {
"type": "integer"
},
"lines": {
"items": {
"properties": {
"addOn": {
"items": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
],
"type": "object"
},
"type": "array"
},
"id": {
"type": "integer"
},
"price": {
"type": "integer"
}
},
"required": [
"id",
"price",
"addOn"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"messageId": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Steve
I would like to append the word "xxx" to the end of the name.
For appending you can directly add while setting the "name" variable.
Alternatively, you can also use concat function as below.
concat(body('Parse_JSON')?['appointment']?['lines'][0]['addOn'][0]['name'],variables('xxx'))
where both cases would give the result as the following
How can I put a proper Condition express to not get any errors or do nothing when there is no addOn array.
You can do this in many ways where one of the workarounds would be using if the lines contain "addOn" or not.
"contains": ["#body('Parse_JSON')?['appointment']?['lines'][0]","addOn"]
MESSAGE1 RESULTS:
MESSAGE2 RESULTS:
You can reproduce the same in your logic app using the below codeview
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "#variables('Message')",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each": {
"actions": {
"Condition": {
"actions": {
"Set_variable": {
"inputs": {
"name": "Message",
"value": {
"appointment": {
"id": "#body('Parse_JSON')?['appointment']?['id']",
"lines": [
{
"addOn": "addOn is NULL",
"id": "#items('For_each')?['id']",
"price": "#items('For_each')?['price']"
}
]
},
"messageId": "#{body('Parse_JSON')?['messageId']}"
}
},
"runAfter": {},
"type": "SetVariable"
}
},
"else": {
"actions": {
"For_each_2": {
"actions": {
"Set_variable_2": {
"inputs": {
"name": "Message",
"value": {
"appointment": {
"id": "#body('Parse_JSON')?['appointment']?['id']",
"lines": [
{
"addOn": [
{
"id": "#items('For_each_2')?['id']",
"name": "#{concat(body('Parse_JSON')?['appointment']?['lines'][0]['addOn'][0]['name'],variables('xxx'))}"
}
],
"id": "#items('For_each')?['id']",
"price": "#items('For_each')?['price']"
}
]
},
"messageId": "#{body('Parse_JSON')?['messageId']}"
}
},
"runAfter": {},
"type": "SetVariable"
}
},
"foreach": "#items('For_each')['addOn']",
"runAfter": {},
"type": "Foreach"
}
}
},
"expression": {
"and": [
{
"not": {
"contains": [
"#body('Parse_JSON')?['appointment']?['lines'][0]",
"addOn"
]
}
}
]
},
"runAfter": {},
"type": "If"
}
},
"foreach": "#body('Parse_JSON')?['appointment']?['lines']",
"runAfter": {
"Initialize_variable_xxx": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Message",
"type": "object"
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_xxx": {
"inputs": {
"variables": [
{
"name": "xxx",
"type": "string",
"value": "xxx"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "#triggerBody()",
"schema": {
"properties": {
"appointment": {
"properties": {
"id": {
"type": "integer"
},
"lines": {
"items": {
"properties": {
"addOn": {
"items": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
],
"type": "object"
},
"type": "array"
},
"id": {
"type": "integer"
},
"price": {
"type": "integer"
}
},
"required": [
"id",
"price"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"messageId": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"appointment": {
"properties": {
"id": {
"type": "integer"
},
"lines": {
"items": {
"properties": {
"addOn": {
"items": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
],
"type": "object"
},
"type": "array"
},
"id": {
"type": "integer"
},
"price": {
"type": "integer"
}
},
"required": [
"id",
"price",
"addOn"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"messageId": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

how to apply if-else for a complex JSON array

here is the Sample Json:-
[
{
"index": 0,
"object": {
"uri": "entities/oAFpSUX",
"type": "configuration/entityTypes/Pet",
"createdBy": "abc#xyz.com",
"createdTime": 1531431176965,
"updatedBy": "abc#xyz.com",
"updatedTime": 1531431177691,
"attributes": {
"Weight": [
{
"label": "5 lbs",
"value": {
"PetWeightMeasurement": [
{
"ov": true,
"value": "5",
}
],
"PetWeightUOM": [
{
"ov": true,
"value": "lbs",
"lookupCode": "lbs",
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Weight/1AeFvD8Kj"
}
],
"Identifiers": [
{
"label": "5155445576",
"value": {
"Type": [
{
"ov": false,
"value": "CRMO_Pet_Id",
}
],
"ID": [
{
"ov": true,
"value": "5155445576",
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Identifiers/1AeFvCrHh"
}
],
"Vaccination": [
{
"label": "Bordatella - 2018-10-26",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Bordatella",
"lookupCode": "4",
"lookupRawValue": "Bordatella",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "3"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/Type/1AeFvA2X7"
}
],
"ExpirationDate": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/ExpirationDate",
"ov": true,
"value": "2018-10-26",
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/ExpirationDate/1AeFvA6nN"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr"
},
{
"label": "Distemper - 2018-10-25",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Distemper",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "4"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9YhJ/Type/1AeFv9cxZ"
}
],....
My question: I was able to get the value of "$..Vaccination..value.Type..value" as "Bordatella" so that works fine. However what I now want is that if the value is 'Bordatella' then I want to extract the "value" under "ExpirationDate". Can someone please help me how I can extract that "value" under "ExpirationDate" ? I am not sure if I need to do that with some custom Groovy code of using jmeter's if controller. Any help would be greatly appreciated!
Thanks.
There are several ways to run jq queries from within Java - e.g.
https://github.com/eiiches/jackson-jq
https://github.com/arakelian/java-jq (available from Maven Central)
Java Native Access wrapper https://github.com/bskaggs/jjq . Supported platform is Linux only.
Assuming the sample input has been revised in the obvious way to make it valid JSON, the following jq filter will produce the output as shown:
.[].object.attributes.Vaccination[].value
| select(.Type[].value == "Bordatella")
| .ExpirationDate[].value
Output:
"2018-10-26"
Alternative
Here's a jq filter that is agnostic about the relative location of the "Vaccination" object:
..
| objects
| select(has("Vaccination"))
| .Vaccination[].value?
| select(.Type[].value == "Bordatella")
| .ExpirationDate[].value
Given the following JSON response:
[
{
"index": 0,
"object": {
"uri": "entities/oAFpSUX",
"type": "configuration/entityTypes/Pet",
"createdBy": "a...#xyz.com",
"createdTime": 1531431176965,
"updatedBy": "a...#xyz.com",
"updatedTime": 1531431177691,
"attributes": {
"Weight": [
{
"label": "5 lbs",
"value": {
"PetWeightMeasurement": [
{
"ov": true,
"value": "5"
}
],
"PetWeightUOM": [
{
"ov": true,
"value": "lbs",
"lookupCode": "lbs"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Weight/1AeFvD8Kj"
}
],
"Identifiers": [
{
"label": "5155445576",
"value": {
"Type": [
{
"ov": false,
"value": "CRMO_Pet_Id"
}
],
"ID": [
{
"ov": true,
"value": "5155445576"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Identifiers/1AeFvCrHh"
}
],
"Vaccination": [
{
"label": "Bordatella - 2018-10-26",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Bordatella",
"lookupCode": "4",
"lookupRawValue": "Bordatella",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "3"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/Type/1AeFvA2X7"
}
],
"ExpirationDate": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/ExpirationDate",
"ov": true,
"value": "2018-10-26",
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/ExpirationDate/1AeFvA6nN"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr"
},
{
"label": "Distemper - 2018-10-25",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Distemper",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "4"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9YhJ/Type/1AeFv9cxZ"
}
]
}
}
]
}
}
}
]
Add JSR223 PostProcessor as a child of the request which returns the above response
Put the following code into "Script" area:
new groovy.json.JsonSlurper().parse(prev.getResponseData()).get(0).get('object').get('attributes').get('Vaccination').each { vaccination ->
if (vaccination.get('value').get('Type').get(0).get('value').equals('Bordatella')) {
def expirationDate = vaccination.get('value').get('ExpirationDate').get(0).get('value')
log.info('ExpirationDate: ' + expirationDate)
vars.put('ExpirationDate', expirationDate)
}
}
If everything goes well (your JSON response matches the Groovy code) the ExpirationDate will be:
printed to jmeter.log file
stored as ${ExpirationDate} JMeter Variable
Demo:
More information:
Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Resources