Get the parent object to use in dojo widget - json

I am trying to parse the json result object and use html template in a widget to display.
The json looks like this
Result": [
{
"Website": "Testing ",
"Description": "Content from yahoo ",
"LinkGroup": {
"entry": [
{
"linkType": "information",
"Link": {
"title": "Test1",
"url": "http://yahoo.com",
"description": "my Link Description"
}
},
{
"linkType": "news link",
"Link": {
"title": "Test 2",
"url": "http://www.yahoo.com/news link...",
"description": "news link Link Description"
}
}
]
}
},
{
"Website": "Testing 2",
"Description": "Content from google ",
"LinkGroup": {
"entry": [
{
"linkType": "information",
"Link": {
"title": "Test1",
"url": "http://google.com",
"description": "my Link Description"
}
},
{
"linkType": "news link",
"Link": {
"title": "Test 2",
"url": "http://www.google.com/news link...",
"description": "news link Link Description"
}
}
]
}
},
I was earlier able to parse just the entry items and used it on a templated widget. I would now like to use the Website and Description object within my widget. Instead of the entry array object I tried to parse the Result object and tried to access the entry. Looking at the console log I see it stops when it tries to get the entry value. I am wondering how to parse it so I can first get the website and description and then add the entry items within that.
This is my html widget code
<div><span title="${Link.description}">${Link.description</span>/div> <br />
${Link.title}<br />
and I parse the json with this code
request("js/my/data/sample.json", {
handleAs: "json"}).then(function(jsonResults){
arrayUtil.forEach(jsonResults.LinksGroup, function(List)
{arrayUtil.forEach(List.LinksGroup.entry, function(Ientry){
var widget = new support(Ientry).placeAt(authorContainer);
});});

I found the answer. I used another widget within the array before the entry object which did the trick.

Related

How to loop through a JSON object with typescript (React)

I am new to React and Typscript and I am trying to loop through a JSON object that I am getting back from a GET request but can't work it out.
i got the following dynamic json data from backend:
{
"G03001784": {
"label": "Important info",
"F03000465": {
"label": "Info hint",
"value": "done"
}
},
"G03003096": {
"label": "Car issue",
"F03004572": {
"label": "has been solved?",
"value": "yes"
},
"F99000187": {
"label": " Car accident",
"value": "two times"
},
"F99000189": {
"label": "New Car",
"value": "200 Euro"
}
}
}
and it should be displayed like this:
Important info
Info hint : done
Car issue
has been solved?: yes
Car accident: two times
New Car: 10000 Euro
Thx a lot in advance

how to use output.integration.slack in Watson Assistant json response

I build a chatbot with Watson Assistant and integrate it with Slack. I want to write Native JSON supported by Slack through Watson Dialog using JSON Editor. The doc of Watson Assistant says:
output.integrations.slack: any JSON response you want to be included in the attachment field of a response intended for Slack.
(see https://cloud.ibm.com/docs/assistant?topic=assistant-dialog-responses-json#dialog-responses-json-user-defined)
So I tried sth like this:
{
"output": {
"integrations": {
"slack": {
"attachment": {
"blocks": [
{
"text": {
"text": "Pick a date for the deadline.",
"type": "mrkdwn"
},
"type": "section",
"accessory": {
"type": "datepicker",
"action_id": "datepicker-action",
"placeholder": {
"text": "Select a date",
"type": "plain_text",
"emoji": true
},
"initial_date": "1990-04-28"
}
}
]
}
}
},
"generic": [
{
"response_type": "text",
"values": [],
"selection_policy": "sequential"
}
]
}
}
The content of the attachment field is copied from the Block Kit Builer(https://api.slack.com/tools/block-kit-builder).
But this seems not work. Can anyone give me some suggestions? Thanks in advance.
Output.integrations is not a preferred way.
Pls try
"output": {
"generic": [
{
"user_defined": {
//Put here your slack attachment
},
"response_type": "user_defined"
}
]}
By using user_defined you can mix with it more responses like text, image, etc.

Google Assistant not showing basic card when responding to action_intent_PERMISSION

I have two intents defined on Dialogflow. Both use a webhook fulfillment implemented in php which returns json.
One of them is activated by the action_intent_PERMISSION event. If the user granted permission, it performs an action and returns both SimpleResponse (text) and a Basic Card with some text and an image.
The problem is that the Basic Card is never shown. In the debug tab of Google Actions Simulator, I can see that the Basic Card is present in the json sent to the assistant, I see it in the Response tab in simulator, but if I look at the Debug tab in simulator, the basic card is not listed under visualElementsList.
The other intent asks user for a zip code, and then performs the same action and returns the same json as the previous intent. In this case, the Basic Card is always shown and I can see it listed under visualElementsList in the Debug tab.
I can't find why the basic card is not displayed at all when the intent is activated by the action_intent_PERMISSION event. I have been researching and looking and can't find it. Thank you for any help.
This is the response tab in simulator for the intent that shows the basic card:
{
"conversationToken": "[\"closestitem\"]",
"finalResponse": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "The item is xxxxx"
}
},
{
"basicCard": {
"title": "Your Closest Item",
"subtitle": "The item is XXXX XXXX XXXX",
"image": {
"url": "https://www.example.com/image.jpg",
"accessibilityText": "Item"
},
"buttons": [
{
"title": "View More",
"openUrlAction": {
"url": "https://www.example.com/"
}
}
]
}
}
]
}
},
"responseMetadata": {
"status": {
"message": "Success (200)"
},
"queryMatchInfo": {
"queryMatched": true,
"intent": "XXXXXXX-2fd7-4ec3-9c88-d90cfccf8661",
"parameterNames": [
"zip"
]
}
}
}
This is the content of the response tab for the intent that is not showing the basic card. I need this basic card to be shown:
{
"conversationToken": "[\"closestitem\",\"closestitem-followup\"]",
"finalResponse": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "The item is XXXXXX"
}
},
{
"basicCard": {
"title": "Your Closest Item",
"subtitle": "The item is XXXXXX.",
"image": {
"url": "https://www.example.com/image.jpg",
"accessibilityText": "Item"
},
"buttons": [
{
"title": "View More",
"openUrlAction": {
"url": "https://www.example.com/"
}
}
]
}
}
]
}
},
"responseMetadata": {
"status": {
"message": "Success (200)"
},
"queryMatchInfo": {
"queryMatched": true,
"intent": "XXXXXXX-3c6d-44fa-b35d-6b097c3da054"
}
}
}
The Errors tab is empty in both cases in simulator.

How to select few elements in json using groovy

I have following json file,
{
"catalog": {
"book": [
{
"id": "bk101",
"author": "Gambardella, Matthew",
"title": "XML Developer's Guide",
"genre": "Computer",
"price": "44.95",
"publish_date": "2000-10-01",
"description": "An in-depth look at creating applications with XML."
},
{
"-id": "bk102",
"author": "Ralls, Kim",
"title": "Midnight Rain",
"genre": "Fantasy",
"price": "5.95",
"publish_date": "2000-12-16",
"description": "A former architect battles "
}
]
}
}
I want to get only few elements from the above, for eg.
catalog.book[0].title should give result
{
"catalog": {
"book": [
{ "title": "XML Developer's Guide"}
]
}
}
But it will give result only {"title": "XML Developer's Guide"}, the tree is missing.
Please help.
you have to create a function which return the subset of json .subset contain all the field you want
//simple javascript code
function subset_of_json(jsonobj,fieldsYouWant){
//fieldsYouWant is an array ['title'] or ['title' ,'id'] or any field you want
var json ={catalog :{book:[]}};
var bookArr =jsonobj.catalog.book;
for(var i=0;i<bookArr.length;i++){
var obj ={};
for(var k=0;k<fieldsYouWant.length;k++){
obj[fieldsYouWant[k]]=bookArr[i][fieldsYouWant[k]];
}
json.catalog.book.push(obj)
}
return json
}

How to use a JSON data source with assemble.io?

The assemble.io documentation gives some examples of using simple JSON as a data source, such as:
{
"title": "Assemble" ,
"author": "Brian Woodward"
}
But, what if I wanted to use a more complex JSON structure for my data (to display a list of books on a single page)? How can that be done?
{
"books": [
{
"title": "Book A",
"author": "Fred"
},
{
"title": "Book 47",
"author": "Joe"
}
]
}
Let say your library.json contain:
{
"books": [
{
"title": "Book A",
"author": "Fred"
},
{
"title": "Book 47",
"author": "Joe"
}
]
}
Use {{each}} (Assemble use handlebarjs for default templating) to display a list of books on a single page:
{{#each library.books}}
{{title}} - {{author}}
{{/each}}