Here i want to read a .json file. I have to read it in controller. But i am getting while reading the .json file.
quiz.json:
[
{
"data":{
"questions":{
"level":[
{
"question":[
{
"title":"What does SAP® stand for?",
"answer":[
"Services for Application Programming",
{
"_correct":"1",
"__text":"Systems, Applications, and Programs"
},
"Sino-American Peace",
"Statistical Analysis Program"
]
},
{
"title":"What does Tcode mean?",
"answer":[
"Television Code",
"Translation Code",
"Transition Code",
{
"_correct":"1",
"__text":"Transaction Code"
}
]
},
}
}
]
I tried to read i got Unexpected token /. Can anyone suggest how to read it?
The JSON you posted was incorrect.
This is the format that needs to be their:
JSON:
$scope.questions = [
{
"data":{
"questions":{
"level":[
{
"question":[
{
"title":"What does SAP® stand for?",
"answer":[
"Services for Application Programming",
{
"_correct":"1",
"__text":"Systems, Applications, and Programs"
},
"Sino-American Peace",
"Statistical Analysis Program"
]
},
{
"title":"What does Tcode mean?",
"answer":[
"Television Code",
"Translation Code",
"Transition Code",
{
"_correct":"1",
"__text":"Transaction Code"
}
]
}
]
}
]
}
}
}
];
and the html that I used to traverse the JSON in angular:
<div ng-app>
<div ng-controller = "test">
<div ng-repeat="data1 in questions">
<div ng-repeat="question in data1.data.questions.level">
<div ng-repeat="levelQuest in question.question">
{{levelQuest.title}}
</div>
</div>
</div>
</div>
</div>
Working Demo
You could paste your JSON structure here - http://jsonformatter.curiousconcept.com/
After pasting you will see that JSON has some errors in its structure.
Correct JSON will be:
[
{
"data":{
"questions":{
"level":[
{
"question":[
{
"title":"What does SAP® stand for?",
"answer":[
"Services for Application Programming",
{
"_correct":"1",
"__text":"Systems, Applications, and Programs"
},
"Sino-American Peace",
"Statistical Analysis Program"
]
},
{
"title":"What does Tcode mean?",
"answer":[
"Television Code",
"Translation Code",
"Transition Code",
{
"_correct":"1",
"__text":"Transaction Code"
}
]
}
]
}
]
}
}
}
]
Related
We are using https://www.npmjs.com/package/botbuilder to build a bot for Microsoft Teams.
We have the following payload to create a card, which has an Input.ChoiceSet inside an Action.ShowCard card.
It works fine when I preview the card from the bar but it doesn't work after I send the card. Sometimes if I restart the MST client it works when I click on a card for the first time but then it doesn't work after that. Sometimes it never works, only from the preview.
It does work fine on Android but it doesn't work on Linux, Mac or web clients.
Here is a demo of the issue, https://www.loom.com/share/7cfec55b587941899cd66e1d896df065
And here is the payload. Try the Click me! button, which should display a dropdown.
{
"type":"message",
"attachments":[
{
"contentType":"application/vnd.microsoft.card.adaptive",
"content":{
"$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
"type":"AdaptiveCard",
"version":"1.2",
"actions":[
{
"type":"Action.OpenUrl",
"title":"Action 1",
"url":"https://my.website.com"
},
{
"type":"Action.Submit",
"title":"Action 2",
"data":{
"command":"action 1",
"data":"asdasd"
}
},
{
"type":"Action.ShowCard",
"title":"Click me!",
"card":{
"type":"AdaptiveCard",
"version":"1.0",
"body":[
{
"type":"Input.ChoiceSet",
"id":"SelectUser",
"style":"compact",
"value":"1",
"choices":[
{
"title":"User 1",
"value":"1"
},
{
"title":"User 2",
"value":"2"
},
{
"title":"User 3",
"value":"3"
}
],
"height":"stretch",
"wrap":true,
"isMultiSelect":false
}
],
"actions":[
{
"type":"Action.Submit",
"title":"Action 3.1",
"data":{
"command":"action 3.1",
"data":"asdasd"
}
}
]
}
},
{
"type":"Action.ShowCard",
"title":"Action 4",
"card":{
"type":"AdaptiveCard",
"body":[
{
"type":"Input.Text",
"label":"Enter comment",
"style":"text",
"id":"text",
"isMultiline":true,
"placeholder":"Enter your comment"
}
],
"actions":[
{
"type":"Action.Submit",
"title":"Save",
"data":{
"command":"save",
"data":"asdasd"
}
}
]
}
}
],
"body":[
{
"type":"TextBlock",
"size":"medium",
"weight":"bolder",
"text":"text... text... text",
"wrap":true
},
{
"type":"ColumnSet",
"columns":[
{
"type":"Column",
"width":"auto",
"items":[
{
"type":"Image",
"style":"Person",
"url":"https://avatar.com/avatar.png",
"size":"small"
}
]
},
{
"type":"Column",
"width":"stretch",
"items":[
{
"type":"TextBlock",
"weight":"lighter",
"text":"text... text... text",
"wrap":true
},
{
"type":"TextBlock",
"spacing":"None",
"text":"text... text... text",
"isSubtle":true,
"wrap":true
}
]
}
]
},
{
"type":"Container",
"items":[
{
"columns":[
{
"spacing":"small",
"width":"auto",
"verticalContentAlignment":"Center",
"type":"Column",
"selectAction":{
"targetElements":[
"fields-content",
"showFields",
"hideFields"
],
"type":"Action.ToggleVisibility",
"title":"expand"
},
"items":[
{
"type":"TextBlock",
"id":"showFields",
"horizontalAlignment":"Left",
"color":"Accent",
"text":"Show fields",
"wrap":true
},
{
"type":"TextBlock",
"id":"hideFields",
"horizontalAlignment":"Left",
"color":"Accent",
"text":"Hide fields",
"wrap":true,
"isVisible":false
}
]
}
],
"type":"ColumnSet"
},
{
"id":"fields-content",
"isVisible":false,
"type":"Container",
"items":[
{
"type":"FactSet",
"facts":[
{
"title":"title",
"value":"value"
}
]
}
]
}
]
}
]
}
}
]
}
Currently we don't have the sample code in nodejs.Agree with you problem in using node library. I too tested with your payload.
We have created bot using Microsoft bot-framework which is integrated to Microsoft teams. We have created few adaptive cards for interactive conversation with bot. One of the Adaptive card is causing design issue in IPhone X Microsoft Teams Application.
We used Adaptive card template for building this card which displays the list of Tasks along with status of the task. Each task has Input.Toggle (Checkbox) and at the end a button will be displayed. When Checkbox's are selected and button is clicked
We are sending new card with task details where they can edit the status and so on. Please find the JSON data below.
Card Payload Editor Json Data:
{
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"border": true,
"items": [
{
"$data": "{properties}",
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"id": "{id}",
"type": "Input.Toggle",
"title": " ",
"value": "false",
"wrap": false
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "Container",
"items": [
{
"type": "FactSet",
"facts": [
{
"$data": "{peers}",
"title": "{key}",
"value": "{value}"
}
]
}
],
"style": "emphasis"
}
]
}
]
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "{actionSubmitTitle}",
"horizontalAlignment": "center"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
Sample Data Editor:
"properties":[
{
"id":"InputToggle1",
"peers":[
{
"key":"Project",
"value":"' .$task->project_name. '"
},
{
"key":"Task",
"value":"'.$task->id.' - '.$task->heading.'"
},
{
"key":"Status",
"value":"'.$task->board_column.'"
}
]
},
{
"id":"InputToggle2",
"peers":[
{
"key":"Project",
"value":"' .$task->project_name. '"
},
{
"key":"Task",
"value":"'.$task->id.' - '.$task->heading.'"
},
{
"key":"Status",
"value":"'.$task->board_column.'"
}
]
},
{
"id":"InputToggle3",
"peers":[
{
"key":"Project",
"value":"' .$task->project_name. '"
},
{
"key":"Task",
"value":"'.$task->id.' - '.$task->heading.'"
},
{
"key":"Status",
"value":"'.$task->board_column.'"
}
]
},
{
"id":"InputToggle4",
"peers":[
{
"key":"Project",
"value":"' .$task->project_name. '"
},
{
"key":"Task",
"value":"'.$task->id.' - '.$task->heading.'"
},
{
"key":"Status",
"value":"'.$task->board_column.'"
}
]
}
],
"actionSubmitTitle":"Update Timesheet"
}
The InputToggle is inside the column set with width as auto and it is perfectly rendering in Microsoft Desktop and Android App but whereas in IOS app it is not showing
When we set the width property to stretch, InputToggle is getting displayed in IOS App in big size but in Desktop App and Android App the column is pushing and occupying much space.
Please help me so that we can display the Input.Toggle in IOS Microsoft Teams without breaking the design in Desktop and Android Teams App.
Edit: Adding final JSON sent to the bot. The columns in the column set will be changed dynamically based on the ask list in database.
{
"type":"AdaptiveCard",
"version":"1.0",
"body":[
{
"type":"Container",
"border":true,
"items":[
{
"type":"ColumnSet",
"columns":[
{
"type":"Column",
"width":"auto",
"items":[
{
"id":"inputToggle1",
"type":"Input.Toggle",
"title":" ",
"value":"false",
"wrap":false
}
]
},
{
"type":"Column",
"width":"stretch",
"items":[
{
"type":"Container",
"items":[
{
"type":"FactSet",
"facts":[
{
"title":"Project",
"value":"Project 1"
},
{
"title":"Task",
"value":"Task 1"
},
{
"title":"Status",
"value":"Pending"
}
]
}
],
"style":"emphasis"
}
]
}
]
},
{
"type":"ColumnSet",
"columns":[
{
"type":"Column",
"width":"auto",
"items":[
{
"id":"inputToggle2",
"type":"Input.Toggle",
"title":" ",
"value":"false",
"wrap":false
}
]
},
{
"type":"Column",
"width":"stretch",
"items":[
{
"type":"Container",
"items":[
{
"type":"FactSet",
"facts":[
{
"title":"Project",
"value":"Project 1"
},
{
"title":"Task",
"value":" Task 2"
},
{
"title":"Status",
"value":"Completed"
}
]
}
],
"style":"emphasis"
}
]
}
]
}
]
}
],
"actions":[
{
"type":"Action.Submit",
"title":"Update Timesheet",
"horizontalAlignment":"center"
}
],
"$schema":"http://adaptivecards.io/schemas/adaptive-card.json"
}
Thank you.
For completion, this was caused by a bug and is tracked as an Github Issue here:
https://github.com/microsoft/AdaptiveCards/issues/4052#
My Telerik MVC Dropdowntree reports the error "Object doesn't support property or method 'level'" for the datasource.
Can someone take a look below and tell me what's wrong?
The MVC looks like this
#(Html.Kendo().DropDownTree()
.Name("dropdowntree")
.DataTextField("Name")
.DataValueField("Id")
.HtmlAttributes(new { style = "width: 100%" })
.DataSource(dataSource => dataSource
.Read(read => read
.Action("DoLayers2", "Dev")
)
)
)
My controller returns the following JSON:
[
{
"Id":1,
"ParentCategoryId":0,
"Name":"First Layer",
"items":[
{
"Id":2,
"ParentCategoryId":1,
"Name":"First SubLayer1",
"items":[
]
},
{
"Id":3,
"ParentCategoryId":1,
"Name":"First SubLayer2",
"items":[
]
},
{
"Id":4,
"ParentCategoryId":1,
"Name":"First SubLayer3",
"items":[
]
}
]
},
{
"Id":5,
"ParentCategoryId":0,
"Name":"Second Layer",
"items":[
{
"Id":6,
"ParentCategoryId":5,
"Name":"Second SubLayer1",
"items":[
]
},
{
"Id":7,
"ParentCategoryId":5,
"Name":"Second SubLayer2",
"items":[
{
"Id":8,
"ParentCategoryId":7,
"Name":"Sub -3",
"items":[
]
}
]
}
]
}
]
Apparently my post has too much code and not enough details so I have to write something foolish at the end of the post to trick the system into allowing me to post it. This is rather annoying.
I'm not sure you can return the whole tree and bind it to the dropdowntree...
If you check telerik's demo you see that they only returns one level at a time, so In your case I think it only wants first level Id:1 and Id:5 at first and then it will automatically ask for second level for each branch...
(Id:1 will return 2, 3, 4 and Id:5 will return 6, 7 and Id:7 will return 8)
You will also have to return if there are any children for each node:
[
{ "Id":1, "Name":"First Layer", "hasChildren": true },
{ "Id":5, "Name":"Second Layer", "hasChildren": true }
]
Hope it helps!
I was able to come up with this:
{
repository(owner: "hawkular", name: "hawkular.github.io") {
pullRequest(number: 237) {
comments(first: 10) {
nodes {
body
author {
login
}
}
}
}
}
}
which returns all the comments on the given PR:
{
"data": {
"repository": {
"pullRequest": {
"comments": {
"nodes": [
{
"body": "PR was auto-deployed here: http://209.132.178.114:10237 and it will be available for 4 days.\n",
"author": {
"login": "hawkular-website-bot"
}
},
{
"body": "Any ETA for this blog post to be finished/published ?",
"author": {
"login": "theute"
}
},
{
"body": "After PR696 in hawkular-metrics I will continue.. helps me to create something repetable",
"author": {
"login": "burmanm"
}
},
{
"body": "PR was auto-deployed here: http://209.132.178.114:10237 and it will be available for 4 days.",
"author": {
"login": "hawkular-website-bot"
}
},
{
"body": "The article cites `CompressionData` job, but it should be `CompressData`.",
"author": {
"login": "jsanda"
}
},
{
"body": "Is this PR active ? Severla months without activity.",
"author": {
"login": "lucasponce"
}
}
]
}
}
}
}
however I am interested only in those written by hawkular-website-bot. Is there a way to specify the author in Git Hub Graph QL api?
There is no filter criterion on the author in type PullRequestConnection. So you can't filter pull requests based on the author. But you can use search query feature like
{
search(query: "repo: hawkular/hawkular.github.io is:pr is:open author:hawkular-website-bot", last:10, type:ISSUE){
edges{
node{
... on PullRequest{
body
title
}
}
}
}
}
For details see this
I want edit the structure of json through Terminal using terminal commands or scripts.
If I have a json file Structure like this:
{
"Helloo": [
{
"AlbumTitle": {
"S": "Famous"
},
"SongTitle": {
"S": "Call Me Today"
},
"Artist": {
"S": "No One You Know"
}
},
{
"AlbumTitle": {
"S": "Famous1"
},
"SongTitle": {
"S": "Call Me Today1"
},
"Artist": {
"S": "No One You Know11"
}
}
],
"Music": [
{
"Album": {
"S": "Pop Songs"
},
"Production": {
"S": "X-series"
},
"Song": {
"S": "Once upon
},
"Artist": {
"S": "XYZ"
}
}
]
}
So here i want add "Putrequest" and "Item" attributes to each item of the array.. So i want the output like this:
{
"Helloo": [
{
PutRequest":{
"Item":{
"AlbumTitle": {
"S": "Famous"
},
"SongTitle": {
"S": "Call Me Today"
},
"Artist": {
"S": "No One You Know"
}
}
}
},
{
PutRequest":{
"Item":{
"AlbumTitle": {
"S": "Famous1"
},
"SongTitle": {
"S": "Call Me Today1"
},
"Artist": {
"S": "No One You Know11"
}
}
}
}
],
"Music": [
{
PutRequest":{
"Item":{
"Album": {
"S": "Pop Songs"
},
"Production": {
"S": "X-series"
},
"Song": {
"S": "Once upon
},
"Artist": {
"S": "XYZ"
}
}
}
}
]
}
I tried to use Jq for this but still struggling.. Please help me To add these attributes to json using command prompt or bash/shell scripting.
Thanks
Assuming you actually got valid JSON the following jq expression might work for you:
map_values(map({"PutRequest": { "Item": .}}))
Usage:
jq 'map_values(map({"PutRequest": { "Item": .}}))' file.json
Breakdown:
map_values( # Map values iterate over an object and assign the
# returned value to the property
map( # Map iterate over an array and assign the returned value
# to the index, and creates a new array if an object is
# mapped
{ # Return an object
"PutRequest": { # With PutRequest as a property
"Item": . # And Item, which contains the value (.)
}
}
)
)