I have a javascript JSON variable and I'm trying to feed it to the JSTree. It is not rendering anything.
{
"id":1,
"data":"GDC",
"depth":-1,
"children":[
{
"id":2,
"data":"SICS",
"depth":0,
"children":[
{
"id":5,
"data":"Collaboration",
"depth":1,
"children":[
{
"id":10,
"data":"Contact Center",
"depth":2,
"children":[
{
"id":607,
"data":"Subscription",
"depth":3,
"children":[
{
"depth":4,
"id":608,
"children":[
],
"data":"Optimization"
}
]
},
{
"id":606,
"data":"Transaction",
"depth":3,
"children":[
{
"depth":4,
"id":664,
"children":[
],
"data":"Planning"
},
{
"depth":4,
"id":672,
"children":[],
}
]
}
]
},
{
"id":11,
"data":"Productivity",
"depth":2,
"children":[
{
"id":1231,
"data":"DevOps",
"depth":3,
"children":[
{
"depth":4,
"id":1280,
"children":[
],
"data":"Deployment"
}
]
},
{
"id":1229,
"data":"Tool Support",
"depth":3,
"children":[
{
"depth":4,
"id":1232,
"children":[
],
"data":"UCDT"
},
{
"depth":4,
"id":1237,
"children":[
],
"data":"PCAT"
}
]
}
]
}
]
},
{
"id":3,
"data":"Security ",
"depth":1,
"children":[
{
"id":284,
"data":"Security",
"depth":2,
"children":[
{
"id":1286,
"data":"Subscription",
"depth":3,
"children":[
{
"depth":4,
"id":1491,
"children":[
],
"data":"Software Strategy"
},
{
"depth":4,
"id":1496,
"children":[
],
"data":"Change Support/Migration"
}
]
},
{
"id":1285,
"data":"Transaction",
"depth":3,
"children":[
{
"depth":4,
"id":1287,
"children":[
],
"data":"CRD"
},
{
"depth":4,
"id":1290,
"children":[
],
"data":"NIP"
}
]
}
]
}
]
}
]
}
]
}
Ive feeded this data into JSTree but its not rendering anything.
I've tried using a basic JSON data, but it takes that. When I have nested children it seems to fail.
th JS code is :
$(function () {
$('#jstree').jstree({
'json_data' : {
'data' : data
}
});
});
Any ideas?
Below is your updated json(change your "data" to "text" property):
var data = {
"id": 1,
"text": "GDC",
"depth": -1,
"children": [
{
"id": 2,
"text": "SICS",
"depth": 0,
"children": [
{
"id": 5,
"text": "Collaboration",
"depth": 1,
"children": [
{
"id": 10,
"text": "Contact Center",
"depth": 2,
"children": [
{
"id": 607,
"text": "Subscription",
"depth": 3,
"children": [
{
"depth": 4,
"id": 608,
"children": [
],
"text": "Optimization"
}
]
},
{
"id": 606,
"text": "Transaction",
"depth": 3,
"children": [
{
"depth": 4,
"id": 664,
"children": [
],
"text": "Planning"
},
{
"depth": 4,
"id": 672,
"children": [],
}
]
}
]
},
{
"id": 11,
"text": "Productivity",
"depth": 2,
"children": [
{
"id": 1231,
"text": "DevOps",
"depth": 3,
"children": [
{
"depth": 4,
"id": 1280,
"children": [
],
"text": "Deployment"
}
]
},
{
"id": 1229,
"text": "Tool Support",
"depth": 3,
"children": [
{
"depth": 4,
"id": 1232,
"children": [
],
"text": "UCDT"
},
{
"depth": 4,
"id": 1237,
"children": [
],
"text": "PCAT"
}
]
}
]
}
]
},
{
"id": 3,
"text": "Security ",
"depth": 1,
"children": [
{
"id": 284,
"text": "Security",
"depth": 2,
"children": [
{
"id": 1286,
"text": "Subscription",
"depth": 3,
"children": [
{
"depth": 4,
"id": 1491,
"children": [
],
"text": "Software Strategy"
},
{
"depth": 4,
"id": 1496,
"children": [
],
"text": "Change Support/Migration"
}
]
},
{
"id": 1285,
"text": "Transaction",
"depth": 3,
"children": [
{
"depth": 4,
"id": 1287,
"children": [
],
"text": "CRD"
},
{
"depth": 4,
"id": 1290,
"children": [
],
"text": "NIP"
}
]
}
]
}
]
}
]
}
]
}
And below is correct js code:
$('#jstree').jstree({
'core': {
'data': data
}
});
Related
BE Response:- which I am getting from Backend Service
{
"data": {
"type": "AnyType",
"resources": [
{
"id": 1,
"treeId": "1",
"name": "name1",
"description": "description1",
"children": [
{
"id": 3,
"treeId": "1-3",
"name": "subName1",
"description": "subDescription1",
"children": [
{
"id": 6,
"treeId": "1-3-6",
"name": "subSubName1",
"description": "subSubDesc1",
"children": []
}
]
}
]
},
{
"id": 2,
"treeId": "2",
"name": "name2",
"description": "description2",
"children": [
{
"id": 7,
"treeId": "2-7",
"name": "subName2",
"description": "subDescription2",
"children": []
}
]
}
]
}
}
But I need to modify this response to as below on FE
Expected Response:- means I need to join name and description field text to one(in name field ) as below:-
{
"data": {
"type": "AnyType",
"resources": [
{
"id": 1,
"treeId": "1",
"name": "name1-description1",
"description": "description1",
"children": [
{
"id": 3,
"treeId": "1-3",
"name": "subName1-subDescription1",
"description": "subDescription1",
"children": [
{
"id": 6,
"treeId": "1-3-6",
"name": "subSubName1-subSubDesc1",
"description": "subSubDesc1",
"children": []
}
]
}
]
},
{
"id": 2,
"treeId": "2",
"name": "name2-description2",
"description": "description2",
"children": [
{
"id": 7,
"treeId": "2-7",
"name": "subName2-subDescription2",
"description": "subDescription2",
"children": []
}
]
}
]
}
}
there could be n number of children of each object and children can have an array of objects.
What I have done:- I am able to change the very first name but not children name
let resDataArry = [];
let descData: DynamicResource;
response.forEach((x, index) => {
const descName = x.name + ' ' + x.description;
descData = { ...tree.resources[index], name: descName };
resDataArry.push(descData);
});
return resDataArry;
Please help.
You can use nested Array#forEach to access children array and then concatenate the name and description together.
let data = {
"data": {
"type": "AnyType",
"resources": [
{
"id": 1,
"treeId": "1",
"name": "name1",
"description": "description1",
"children": [
{
"id": 3,
"treeId": "1-3",
"name": "subName1",
"description": "subDescription1",
"children": [
{
"id": 6,
"treeId": "1-3-6",
"name": "subSubName1",
"description": "subSubDesc1",
"children": []
}
]
}
]
},
{
"id": 2,
"treeId": "2",
"name": "name2",
"description": "description2",
"children": [
{
"id": 7,
"treeId": "2-7",
"name": "subName2",
"description": "subDescription2",
"children": []
}
]
}
]
}
}
data.data.resources.forEach(function(item){
item.name = item.name + ' ' + item.description;
item.children.forEach(function(child){
child.name = child.name + ' ' + child.description;
});
});
console.log(data);
let obj = {
"options": [
{
"id": "a",
"name": "a",
"options": [
{
"id": "a.1",
"options": [
{
"id": "a.1.1",
"name": "a.1.1"
},
{
"id": "a.1.2",
"name": "a.1.2"
},
{
"id": "a.1.3",
"name": "a.1.3"
}
]
},
{
"id": "a.2",
"name": "a.2",
"options": [
{
"id": "a.2.1",
"name": "a.2.1"
},
{
"id": "a.2.2",
"name": "a.2.2"
},
{
"id": "a.2.3",
"name": "a.2.3"
}
]
},
{
"id": "a.3",
"name": "a.3",
"options": [
{
"id": "a.3.1",
"name": "a.3.1"
},
{
"id": "a.3.2",
"name": "a.3.1"
},
{
"id": "a.3.3",
"name": "a.3.1"
}
]
}
]
},
{
"name": "b",
"id": "b",
"options": [
{
"id": "b.1",
"name": "b.1",
"options": [
{
"id": "b.1.1",
"name": "b.1.1"
},
{
"id": "b.1.2",
"name": "b.1.2"
},
{
"id": "b.1.3",
"name": "b.1.3"
}
]
},
{
"id": "b.2",
"name": "b.2",
"options": [
{
"id": "b.2.1",
"name": "b.2.1"
},
{
"id": "b.2.2",
"name": "b.2.2"
},
{
"id": "b.2.3",
"name": "b.2.3"
}
]
},
{
"id": "b.3",
"name": "b.3.1",
"options": [
{
"id": "b.3.1",
"name": "b.3.1"
},
{
"id": "b.3.2",
"name": "b.3.2"
},
{
"id": "b.3.3",
"name": "b.3.3"
}
]
}
]
},
{
"id": "c",
"name": "c",
"options": [
{
"id": "c.1",
"name": "c.1",
"options": [
{
"id": "c.1.1",
"name": "c.1.1"
},
{
"id": "c.1.2",
"name": "c.1.2"
},
{
"id": "c.1.3",
"name": "c.1.3"
}
]
},
{
"id": "c.2",
"name": "c.2",
"options": [
{
"id": "c.2.1",
"name": "c.2.1"
},
{
"id": "c.2.2",
"name": "c.2.2"
},
{
"id": "c.2.3",
"name": "c.2.3"
}
]
},
{
"id": "c.3",
"name": "c.3",
"options": [
{
"id": "c.3.1",
"name": "c.3.1"
},
{
"id": "c.3.2",
"name": "c.3.2"
},
{
"id": "c.3.3",
"name": "c.3.3"
}
]
}
]
}
]
}
" I have this object
I neeed to create a function getHierarchy, that an option ID as its input, finds the option in the
list and returns the ID of all it's parents.
for example,getHierarchy("a.1.3") should return the following result ["a","a.1","a.1.3"]
getHierarchy("c.3.3") should return the following result ["c","c.3","c.3.3"] "
assuming id is unique;
function getHierarchy(object, id, prev) {
if (!object.options) return;
for (const child of object.options) {
if(child.id === id) {
return [...prev, object.id, child.id];
}
result = getHierarchy(child, id, [...prev, object.id]);
if (result) return result;
}
}
getHierarchy(obj, "a.1.3", []);
Here an recursive solution i hope this helps you.
let obj = {
"options": [
{
"id": "a",
"name": "a",
"options": [
{
"id": "a.1",
"options": [
{
"id": "a.1.1",
"name": "a.1.1"
},
{
"id": "a.1.2",
"name": "a.1.2"
},
{
"id": "a.1.3",
"name": "a.1.3"
}
]
},
{
"id": "a.2",
"name": "a.2",
"options": [
{
"id": "a.2.1",
"name": "a.2.1"
},
{
"id": "a.2.2",
"name": "a.2.2"
},
{
"id": "a.2.3",
"name": "a.2.3"
}
]
},
{
"id": "a.3",
"name": "a.3",
"options": [
{
"id": "a.3.1",
"name": "a.3.1"
},
{
"id": "a.3.2",
"name": "a.3.1"
},
{
"id": "a.3.3",
"name": "a.3.1"
}
]
}
]
},
{
"name": "b",
"id": "b",
"options": [
{
"id": "b.1",
"name": "b.1",
"options": [
{
"id": "b.1.1",
"name": "b.1.1"
},
{
"id": "b.1.2",
"name": "b.1.2"
},
{
"id": "b.1.3",
"name": "b.1.3"
}
]
},
{
"id": "b.2",
"name": "b.2",
"options": [
{
"id": "b.2.1",
"name": "b.2.1"
},
{
"id": "b.2.2",
"name": "b.2.2"
},
{
"id": "b.2.3",
"name": "b.2.3"
}
]
},
{
"id": "b.3",
"name": "b.3.1",
"options": [
{
"id": "b.3.1",
"name": "b.3.1"
},
{
"id": "b.3.2",
"name": "b.3.2"
},
{
"id": "b.3.3",
"name": "b.3.3"
}
]
}
]
},
{
"id": "c",
"name": "c",
"options": [
{
"id": "c.1",
"name": "c.1",
"options": [
{
"id": "c.1.1",
"name": "c.1.1"
},
{
"id": "c.1.2",
"name": "c.1.2"
},
{
"id": "c.1.3",
"name": "c.1.3"
}
]
},
{
"id": "c.2",
"name": "c.2",
"options": [
{
"id": "c.2.1",
"name": "c.2.1"
},
{
"id": "c.2.2",
"name": "c.2.2"
},
{
"id": "c.2.3",
"name": "c.2.3"
}
]
},
{
"id": "c.3",
"name": "c.3",
"options": [
{
"id": "c.3.1",
"name": "c.3.1"
},
{
"id": "c.3.2",
"name": "c.3.2"
},
{
"id": "c.3.3",
"name": "c.3.3"
}
]
}
]
}
]
}
function getHierarchy(opts, path, index = 1, result = []) {
if(!opts) return result;
let objPaths = path.split(".");
let _path = objPaths.slice(0, index).join(".");
let option = opts.find(({id}) => id === _path);
if(!option) return result;
let { options, id } = option;
return getHierarchy(options, path, ++index, [...result,id]);
}
let result = getHierarchy(obj.options, "a.1.3");
console.log(result);
I am making a project for my school in JavaScript. I am trying to code an Alexa skill which allows for students to receive information about their teacher's availabilities. I am a novice, and I am trying to resolve an error in which it is saying "Expected "," but saw "i" right before the if statement on Line 423. When I try to add a comma on line 421, it moves the error to that line. I cannot remove the error unless I delete the entire if statement. The if statement is to test where my skill will allow for an emission of a response from Alexa. Thank you for any help I receive!
Below is the code.
{
"languageModel": {
"types": [
{
"name": "teacher",
"values": [
{
"id": "teacherTyrrell",
"name": {
"value": "Dr. Tyrrell",
"synonyms": [
"Mrs. Tee-Rull",
"Ms. Tee-Rull",
"Maygrace Tee-Rull",
"Dr. Tee-rull",
"Ms. Tyrrell",
"Miss Tyrrell",
"Mrs. Tyrrell",
"Marygrace Tyrrell"
]
}
},
{
"id": "teacherTwyford",
"name": {
"value": "Mr. Twyford",
"synonyms": [
"Marcus Twyford"
]
}
},
{
"id": "teacherThornberry",
"name": {
"value": "Miss Thornberry",
"synonyms": [
"Chantal Thornberry",
"Mrs. Thornberry",
"Chantal"
]
}
},
{
"id": "teacherSuarez",
"name": {
"value": "Mrs. Suarez",
"synonyms": [
"Miss Suarez",
"Angela Suarez",
"Señora Suarez"
]
}
},
{
"id": "teacherRobtaille",
"name": {
"value": "Mrs. Robataille",
"synonyms": [
"Señora Robitaille",
"Patricia Robe-a-tye",
"Patricia Robitaille",
"Señora Robe-a-tye",
"Mrs. Robe-a-tye"
]
}
},
{
"id": "teacherPhillips",
"name": {
"value": "Miss Phillips",
"synonyms": [
"Catherine Phillips",
"Ms. Phillips",
"Mrs. Phillips"
]
}
},
{
"id": "teacherPeterson",
"name": {
"value": "Mr. Peterson",
"synonyms": [
"Eric Peterson"
]
}
},
{
"id": "teacherNeugebauer",
"name": {
"value": "Mr. Neugebauer",
"synonyms": [
"Dan Noogabower",
"Dan Neugebauer",
"Mr. Noogabower"
]
}
},
{
"id": "teacherMiller",
"name": {
"value": "Mr. Miller",
"synonyms": [
"Brock Miller"
]
}
},
{
"id": "teacherMcGivern",
"name": {
"value": "Mr. McGivern",
"synonyms": [
"Chucky Mcgivern",
"Charles McGivern",
"Chucky",
"McGivern"
]
}
},
{
"id": "teacherMcCall",
"name": {
"value": "Dr. McCall",
"synonyms": [
"Jeremiah McCall",
"Mr. McCall",
"D-Mac"
]
}
},
{
"id": "teacherLichtySmith",
"name": {
"value": "Miss Lichty-Smith",
"synonyms": [
"Carole Lichty-Smith",
"Mrs. Lichty-Smith",
"Ms. L",
"Mrs. L"
]
}
},
{
"id": "teacherKim",
"name": {
"value": "Miss Kim",
"synonyms": [
"Jesse Kim",
"The health teacher",
"Mrs. Kim"
]
}
},
{
"id": "teacherKairet",
"name": {
"value": "Dr. Kairet",
"synonyms": [
"mrs. curray",
"miss curray",
"mrs. kairet",
"Miss kairet",
"madame kairet",
"madame curray",
"Madame currae"
]
}
},
{
"id": "teacherHecker",
"name": {
"value": "Dr. Hecker",
"synonyms": [
"Jeanette Hecker",
"Miss Hecker",
"Madame Hecker",
"Mrs. Hecker"
]
}
},
{
"id": "teacherFranzosa",
"name": {
"value": "Dr. Franzosa",
"synonyms": [
"Mr. Franzosa",
"Jonathon Franzosa",
"D-Fran"
]
}
},
{
"id": "teacherFossett",
"name": {
"value": "Mr. Fossett",
"synonyms": [
"Peter Fossett"
]
}
},
{
"id": "tecaherFloyd",
"name": {
"value": "Miss Floyd",
"synonyms": [
"Deborah Floyd",
"Ms. Floyd",
"Mrs. Floyd"
]
}
},
{
"id": "teacherFaulhaber",
"name": {
"value": "Mr. Faulhaber",
"synonyms": [
"Gregory Faulhaber",
"G-Faul"
]
}
},
{
"id": "teacherTDunn",
"name": {
"value": "Mr. Dunn",
"synonyms": [
"The GOAT",
"Timothy Dunn",
"T-Dunn"
]
}
},
{
"id": "teacherPDunn",
"name": {
"value": "Mrs. Dunn",
"synonyms": [
"P-Dunn",
"Miss Dunn",
"Patricia Dunn"
]
}
},
{
"id": "teacherDestin",
"name": {
"value": "Dr. Destin",
"synonyms": [
"Yven Destin",
"Mr. Destin"
]
}
},
{
"id": "teacherDahl",
"name": {
"value": "Mr. Dahl",
"synonyms": [
"Matthew Dahl"
]
}
},
{
"id": "teacherLChristiansen",
"name": {
"value": "Mrs. Christiansen",
"synonyms": [
"Laura Christiansen"
]
}
},
{
"id": "teacherJChristiansen",
"name": {
"value": "Mr. Christiansen",
"synonyms": [
"John Christiansen"
]
}
},
{
"id": "teacherCastro",
"name": {
"value": "Mrs. Castro",
"synonyms": [
"Mrs. Castro",
"Malena Castro",
"Señora Castro"
]
}
},
{
"id": "teacherButler",
"name": {
"value": "Mrs. Butler",
"synonyms": [
"Miss Butler",
"Paula Butler"
]
}
},
{
"id": "teacherBrand",
"name": {
"value": "Ms. Brand",
"synonyms": [
"Amy Brand",
"Mrs. Brand",
"Miss Brand"
]
}
},
{
"id": "teacherBodollo",
"name": {
"value": "Mrs. Bodollo",
"synonyms": [
"Lisa Bodollo",
"Miss Bodollo"
]
}
},
{
"id": "teacherBlack",
"name": {
"value": "Mr. Black",
"synonyms": [
"Merle Black",
"Merle"
]
}
},
{
"id": "teacherBack",
"name": {
"value": "Mrs. Back",
"synonyms": [
"Jamie Back"
]
}
}
]
}
],
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "dailySchedule",
"samples": [
"What is the bell schedule",
"What's the schedule today",
"What is the schedule today"
],
"slots": []
},
{
"name": "teacherFreeBell",
"samples": [
"Is {teacher} free ",
"Is {teacher} free right now",
"What free bells does {teacher} have today",
"What free bells does {teacher} have",
"When is {teacher} free"
],
"slots": [
{
"name": "teacher",
"type": "teacher"
}
]
},
{
"name": "whatBell",
"samples": [
"What bell is it",
"What bell is right now"
],
"slots": []
}
],
"invocationName": "country day"
},
"prompts": [
{
"id": "Elicit.Intent-teacherFreeBell.IntentSlot-teacher",
"variations": [
{
"type": "PlainText",
"value": "Which teacher are you asking about?"
},
{
"type": "PlainText",
"value": "Who is the teacher?"
}
]
}
],
"dialog": {
"intents": [
{
"name": "teacherFreeBell",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "teacher",
"type": "teacher",
"elicitationRequired": true,
"confirmationRequired": false,
"prompts": {
"elicitation": "Elicit.Intent-teacherFreeBell.IntentSlot-teacher"
}
if IntentSlot(teacher) = teacherBack
{
this.emit("this is working")
}
}
]
}
]
}
}
https://pastebin.com/VyctHsbS
You cannot have an if statement inside the schema json
If you'd like to test where the skill will allow for an emission do it in the skill code.
Your skill needs to have an end point for you to send a reponse to the user, you can do that with your own service, or use a lambda function
** for more information on skill schemas check the alexa documentation
I have a raw data like this:
var data = {
"issues": [
{
"fields": {
"project": {
"key": "ProjectA"
},
"components": [
{
"name": "Component A"
},
{
"name": "Component C"
}
],
"priority": {
"name": "P0"
},
"status": {
"name": "Closed"
}
}
},
{
"fields": {
"project": {
"key": "ProjectA"
},
"components": [
{
"name": "Component B"
}
],
"priority": {
"name": "P1"
},
"status": {
"name": "Reopened"
}
}
},
{
"fields": {
"project": {
"key": "ProjectA"
},
"components": [
{
"name": "Component B"
}
],
"priority": {
"name": "P1"
},
"status": {
"name": "Closed"
}
}
},
{
"fields": {
"project": {
"key": "Project B"
},
"components": [
{
"name": "Component X"
}
],
"priority": {
"name": "P1"
},
"status": {
"name": "Closed"
}
}
}
]
};
If I give ProjectA as input, I would like to filter, group and aggregate the output as follows:
"components": [
{
"name": "Component A",
"priorities": [
{
"name": "P0",
"status": [
{
"name": "Open",
"count": 0
},
{
"name": "Reopened",
"count": 0
},
{
"name": "Closed",
"count": 1
}
]
},
{
"name": "P1",
"status": [
{
"name": "Open",
"count": 0
},
{
"name": "Reopened",
"count": 0
},
{
"name": "Closed",
"count": 0
}
]
}
]
},
{
"name": "Component B",
"priorities": [
{
"name": "P0",
"status": [
{
"name": "Open",
"count": 0
},
{
"name": "Reopened",
"count": 0
},
{
"name": "Closed",
"count": 0
}
]
},
{
"name": "P1",
"status": [
{
"name": "Open",
"count": 0
},
{
"name": "Reopened",
"count": 1
},
{
"name": "Closed",
"count": 1
}
]
}
]
},
{
"name": "Component C",
"priorities": [
{
"name": "P0",
"status": [
{
"name": "Open",
"count": 0
},
{
"name": "Reopened",
"count": 0
},
{
"name": "Closed",
"count": 1
}
]
},
{
"name": "P1",
"status": [
{
"name": "Open",
"count": 0
},
{
"name": "Reopened",
"count": 0
},
{
"name": "Closed",
"count": 0
}
]
}
]
}
]
I tried chaining, filtering, grouping, but not sure how to use this, since my data is too nested.
This is a proposal in plain javascript with first collecting all components and priorities and build then a result object and later increment the count of the status.
var data = { "issues": [{ "fields": { "project": { "key": "ProjectA" }, "components": [{ "name": "Component A" }, { "name": "Component C" }], "priority": { "name": "P0" }, "status": { "name": "Closed" } } }, { "fields": { "project": { "key": "ProjectA" }, "components": [{ "name": "Component B" }], "priority": { "name": "P1" }, "status": { "name": "Reopened" } } }, { "fields": { "project": { "key": "ProjectA" }, "components": [{ "name": "Component B" }], "priority": { "name": "P1" }, "status": { "name": "Closed" } } }, { "fields": { "project": { "key": "Project B" }, "components": [{ "name": "Component X" }], "priority": { "name": "P1" }, "status": { "name": "Closed" } } }] },
componentsO = Object.create(null),
prioritiesO = Object.create(null),
components,
priorities,
status_ = ['Open', 'Reopened', 'Closed'], // status collides in chrome with window.status
hash = Object.create(null),
getKey = function (a) { return a.join('|'); },
result = {};
data.issues.forEach(function (issue) {
if (issue.fields.project.key === 'ProjectA') {
issue.fields.components.forEach(function (component) {
componentsO[component.name] = true;
});
prioritiesO[issue.fields.priority.name] = true;
}
});
components = Object.keys(componentsO).sort();
priorities = Object.keys(prioritiesO).sort();
result.components = components.map(function (component) {
return {
name: component,
priorities: priorities.map(function (priority) {
return {
name: priority,
status: status_.map(function (status) {
var key = getKey([component, priority, status]);
hash[key] = { name: status, count: 0 };
return hash[key];
})
};
})
}
});
data.issues.forEach(function (issue) {
if (issue.fields.project.key === 'ProjectA') {
issue.fields.components.forEach(function (component) {
var key = getKey([component.name, issue.fields.priority.name, issue.fields.status.name]);
hash[key].count++;
});
}
});
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
I am getting an array of specs from flipkart's API.
I am able to get this response from that API:
{
"nextUrl": "https://affiliate-api.flipkart.net/1.0/affiliate/feeds/fnkygygma/category/reh/55ab6c2673a4773ffb8e4019.json?expiresAt=1452881213871&sig=1c4c5111b6b014a71a17b229e6df6afc",
"validTill": 1452881213871,
"productInfoList": [
{
"productBaseInfoV1": {
"productId": "TDHDMH5GRSPZ3DNM",
"title": "Newhide Designer",
"productDescription": "",
"imageUrls": {
"400x400": "http://img.fkcdn.com/image/travel-document-holder/d/n/m/cdbp040739-newhide-passport-holder-designer-400x400-imadmh8zgxbrsgq6.jpeg",
"200x200": "http://img.fkcdn.com/image/travel-document-holder/d/n/m/cdbp040739-newhide-passport-holder-designer-200x200-imadmh8zgxbrsgq6.jpeg",
"unknown": "http://img.fkcdn.com/image/travel-document-holder/d/n/m/cdbp040739-newhide-passport-holder-designer-original-imadmh8zgxbrsgq6.jpeg",
"800x800": "http://img.fkcdn.com/image/travel-document-holder/d/n/m/cdbp040739-newhide-passport-holder-designer-800x800-imadmh8zgxbrsgq6.jpeg"
},
"productFamily": null,
"maximumRetailPrice": {
"amount": 1145,
"currency": "INR"
},
"flipkartSellingPrice": {
"amount": 1145,
"currency": "INR"
},
"flipkartSpecialPrice": {
"amount": 1145,
"currency": "INR"
},
"productUrl": "http://dl.flipkart.com/dl/newhide-designer/p/itmdp2nunbzffwzr?pid=TDHDMH5GRSPZ3DNM&affid=keshav",
"productBrand": "Newhide",
"inStock": true,
"codAvailable": true,
"discountPercentage": 0,
"offers": [],
"categoryPath": "[[{\"node_id\":20001,\"node_name\":\"FLIPKART_TREE\"},{\"node_id\":21183,\"node_name\":\"Lifestyle\"},{\"node_id\":21499,\"node_name\":\"Leather \\u0026 Travel Accessories\"},{\"node_id\":21960,\"node_name\":\"Wallets \\u0026 Clutches\"},{\"node_id\":21274,\"node_name\":\"Wallets \\u0026 Card Wallets\"}]]",
"styleCode": null,
"attributes": {
"size": "",
"color": "Black",
"storage": "",
"sizeUnit": "",
"displaySize": ""
}
},
"productShippingInfoV1": {
"shippingCharges": {
"amount": 0,
"currency": "INR"
},
"sellerName": null,
"sellerAverageRating": null,
"sellerNoOfRatings": 0,
"sellerNoOfReviews": 0
},
"categorySpecificInfoV1": {
"keySpecs": [
"Passport Holder",
"Passport Wallet"
],
"detailedSpecs": [],
"specificationList": [
{
"key": "General",
"values": [
{
"key": "Type",
"value": [
"Passport Organizer"
]
},
{
"key": "Ideal For",
"value": [
"Men's, Women's"
]
},
{
"key": "Material",
"value": [
"Leather, Cloth"
]
},
{
"key": "Slot for Cards",
"value": [
"Yes"
]
},
{
"key": "Slot for Passport",
"value": [
"Yes"
]
},
{
"key": "Slot for Cheque Book",
"value": [
"Yes"
]
},
{
"key": "Style Code",
"value": [
"CDBP040739"
]
},
{
"key": "Color Code",
"value": [
"Black"
]
}
]
},
{
"key": "Warranty",
"values": [
{
"key": " ",
"value": [
"1 Year Newhide warranty"
]
}
]
}
],
"booksInfo": {
"language": null,
"binding": null,
"pages": null,
"publisher": null,
"year": 0,
"authors": []
},
"lifeStyleInfo": {
"sleeve": null,
"neck": null,
"idealFor": [
"Men's",
"Women's"
]
}
}
}
}
I and not able decode
"categorySpecificInfoV1": {
"keySpecs": [
"Passport Holder",
"Passport Wallet"
],
I have tried json_decode. This gives error
Warning: json_decode() expects parameter 1 to be string, array given.
$keySpecs=$product['categorySpecificInfoV1']['keySpecs'];
$ar = json_decode($keySpecs,true);
I am new to PHP, how can I print the keyspecs from keyspecs array?
The warning is pretty clear. You need to pass the entire string you obtained from Flipkart into the json_decode() function.
See Documentation
$ar = json_decode($flipkart_result, true);
print_r($ar); //to check the array.
print_r($ar['categorySpecificInfoV1']['keySpecs']);
This should do. Post more information if this does not help.