paring json array in php from api - javascript

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.

Related

react-checkbox-tree doesn't expand

I am new to react. I created a checkbox tree with the react-checkbox-tree package. The problem is when I click on an item in the tree, it doesn't expand when it should.
What changes can I make to fix it
Thanks in advance...
Here sandbox link of the app : sandbox
Here is my JSON database :
[
{
"mailProcessingCenters": [
{
"value": "AEAUHA",
"name": "ABU DHABI"
},
{
"value": "AEDXBA",
"name": "DUBAI"
},
{
"value": "AEDXBB",
"name": "DUBAI RASID SEA-PORT"
},
{
"value": "AEDXBD",
"name": "DUBAI TRANSIT / HUB"
},
{
"value": "AEDXBE",
"name": "DUBAI - SOMALIA"
},
{
"value": "AUSYDK",
"name": "SYDNEY K (EMIRATES - DIRECT LINK)"
},
{
"value": "GBLONO",
"name": "LONDON"
},
{
"value": "SGSINO",
"name": "SINGAPORE"
},
{
"value": "SGSINQ",
"name": "SINGAPORE Q, UAE"
},
{
"value": "USCHIE",
"name": "CHICAGO E"
},
{
"value": "USJECU",
"name": "NEW JERSEY U EMIRATES POST"
}
],
"value": "J1CAEA",
"shortvalue": "AEA",
"label": "EmiratesPost"
},
{
"mailProcessingCenters": [
{
"value": "AFKBLA",
"name": "KABUL"
},
{
"value": "AFKBLC",
"name": "KABUL C"
},
{
"value": "AFKBLS",
"name": "KABUL EMS SHAHEEN POST"
}
],
"value": "J1CAFA",
"shortvalue": "AFA",
"label": "Afghan Post"
},
{
"mailProcessingCenters": [
{
"value": "AGANUA",
"name": "ST JOHNS, A, ANTIGUA AND BARBUDA"
},
{
"value": "AGANUB",
"name": "ST JOHNS, B, ANTIGUA AND BARBUDA"
},
{
"value": "AGANUC",
"name": "ST JOHNS, C, ANTIGUA AND BARBUDA"
}
],
"value": "J1CAGA",
"shortvalue": "AGA",
"label": "GPO Antigua"
},
{
"mailProcessingCenters": [],
"value": "J1CAIA",
"shortvalue": "AIA",
"label": "AnguillaPost"
},
{
"mailProcessingCenters": [
{
"value": "ALTIAA",
"name": "TIRANA ENTRANGER"
}
],
"value": "J1CALA",
"shortvalue": "ALA",
"label": "Albanian PT"
},
{
"mailProcessingCenters": [
{
"value": "AMEVNA",
"name": "YEREVAN"
},
{
"value": "AMEVNB",
"name": "YEREVAN PI-2"
},
{
"value": "AMEVNC",
"name": "YEREVAN PI-3"
},
{
"value": "AMEVND",
"name": "YEREVAN EMS"
}
],
"value": "J1CAMA",
"shortvalue": "AMA",
"label": "Haypost AM"
},
{
"mailProcessingCenters": [],
"value": "J1CANA",
"shortvalue": "ANA",
"label": "POST NA NV"
}
]
And here is my App.js :
class App extends React.Component {
state = {
checked: [],
expanded: [],
database: db
};
render() {
console.log(this.state);
return (
<div>
<div onClick={secildi}>
<CheckboxTree
nodes={this.state.database}
checked={this.state.checked}
expanded={this.state.expanded}
onCheck={checked => this.setState({ checked })}
onExpand={expanded => this.setState({ expanded })}
/>
</div>
<div />
</div>
);
}
}
You have to rename the mailProcessingCenters to children and as suggested by Nicolò Cozzani name should have to be renamed as label.
I can see in the react-checkbox-tree demo, they require the children array to make it a tree which gets expanded.
const nodes = [{
value: 'mars',
label: 'Mars',
children: [ //<--------this one
{ value: 'phobos', label: 'Phobos' }, // <----name should be renamed as label
{ value: 'deimos', label: 'Deimos' },
],
}];
Updated code sand box.

merging the keys inside an object with checking two dimensional arary

how to merge the keys in the array into a single key with using the seperator, if value is null dont take it
let keysToBeMerged = [['note', 'status', seperator: ' ,'], ['group', 'level', seperator: ' ()']];
let data = [
{
"fields": [
{
"key": "area",
"value": null
},
{
"key": "terminal",
"value": null
},
{
"key": "note",
"value": "Some key notes"
},
{
"key": "status",
"value": "Enabled"
},
{
"key": "group",
"value": "Medium"
},
{
"key": "level",
"value": null
}
],
"name": "test 1",
"number": "123456127890",
"id": "yqweyqweu213"
},
{
"fields": [
{
"key": "area",
"value": "Delhi"
},
{
"key": "terminal",
"value": null
},
{
"key": "note",
"value": "Some key orginal notes"
},
{
"key": "status",
"value": "Disabled"
},
{
"key": "group",
"value": "Medium"
},
{
"key": "level",
"value": "High"
}
],
"name": "test 2",
"number": "173276123612",
"id": "uqweyewueyyuqwe"
},
{
"fields": [
{
"key": "area",
"value": "Mumbai"
},
{
"key": "terminal",
"value": 1
},
{
"key": "note",
"value": "Some key orginal sample notes"
},
{
"key": "status",
"value": "Enabled"
},
{
"key": "group",
"value": "Low"
},
{
"key": "level",
"value": null
}
],
"name": "test 3",
"number": "128737812381723",
"id": "kasjdashdkaskjd"
}
]
i have a collection called keysToBeMerged, i need to find the key from the he fields collection and need to merge some keys into a single key with merged values with using the seperator.
tried with below snippet
data.map(o => {
let key = []
let value = []
o.fields.forEach(f => {
keysToBeMerged.forEach(kColl => {
if(kColl.includes(f.key)){
key.push(f.key)
value.push(f.value)
}
})
console.log(key.join(""))
console.log(value.join(""))
})
return o
})
the expectedResult is shown below. Any help appreciated
let expectedResult = [
{
"fields": [
{
"key": "area",
"value": null
},
{
"key": "terminal",
"value": null
},
{
"key": "note|status",
"value": "Some key notes, Enabled"
},
{
"key": "group|level",
"value": "Medium"
}
],
"name": "test 1",
"number": "123456127890",
"id": "yqweyqweu213"
},
{
"fields": [
{
"key": "area",
"value": "Delhi"
},
{
"key": "terminal",
"value": null
},
{
"key": "note|status",
"value": "Some key orginal notes, Disabled"
},
{
"key": "group|level",
"value": "Medium (High)"
},
],
"name": "test 2",
"number": "173276123612",
"id": "uqweyewueyyuqwe"
},
{
"fields": [
{
"key": "area",
"value": "Mumbai"
},
{
"key": "terminal",
"value": 1
},
{
"key": "note|status",
"value": "Some key orginal sample notes, Enabled"
},
{
"key": "group|level",
"value": "Low"
},
],
"name": "test 3",
"number": "128737812381723",
"id": "kasjdashdkaskjd"
}
]

Check if a nested array contains any element of another nested array in JavaScript

I have 2 nested array and I want to check if id's from the list1 and if there are same id in the list2 add that object of the list2 + tag and count from the list1 to a new array.New array has the tag,count and the list of details of id that is in the list1 and is same as id in the list2
Note: these 2 lists doesn't have the same size
Thank in advance for help
For example:
list1
const list1 = [
{
"id": [
"5cca1dbc-dd5c-498f-8f83-735062c05240",
"2a10c30a-7c3a-4081-8246-9d37e19c2d6f",
"3128f36c-1c79-4301-b08f-e0182c256c03"
],
"tag": "tag1",
"count": {
"low": 53,
"high": 0
}
},
{
"id": [
"510019af-1728-4628-9019-343cd3c1b3e1",
"fb420746-4d11-4d2e-ab7f-b8a73e5b8f8e",
"adf0cd4c-3072-4ecf-9aa7-ecd5580c31ae"
],
"tag": "tag2",
"count": {
"low": 43,
"high": 0
}
}
]
list2
[
{
"id": "5cca1dbc-dd5c-498f-8f83-735062c05240",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [
{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}
],
"topics": [
{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
},
{
"id": "fb420746-4d11-4d2e-ab7f-b8a73e5b8f8e",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [
{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}
],
"topics": [
{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
},
{
"id": "efde2bc9-018b-49c1-9c01-a4eda9817a33",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [
{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}
],
"topics": [
{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
}
]
new array
[
{
"tag": "tag1",
"count": {
"low": 53,
"high": 0
},
"details": [
{
"id": "5cca1dbc-dd5c-498f-8f83-735062c05240",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [
{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}
],
"topics": [
{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
}
]
}
]
Iterate through list1, check if the id exists in list2 and if it does add it to a new array.
e.g.
var result = [];
for (let item of list1) {
let details = list2.filter(l2 => item.id.includes(l2.id));
if (details.length > 0) {
result.push({
tag: item.tag,
count: item.count,
details: details
});
}
}
If you want all items in list1 to show up regardless of the id existing in list2 you could use map and return a new object for each item in list1.
var result = list1.map(l1 => {
return {
tag: l1.tag,
count: l1.count,
details: list2.filter(l2 => l1.id.includes(l2.id))
};
});
const list1 = [{
"id": [
"5cca1dbc-dd5c-498f-8f83-735062c05240",
"2a10c30a-7c3a-4081-8246-9d37e19c2d6f",
"3128f36c-1c79-4301-b08f-e0182c256c03"
],
"tag": "tag1",
"count": {
"low": 53,
"high": 0
}
},
{
"id": [
"510019af-1728-4628-9019-343cd3c1b3e1",
"fb420746-4d11-4d2e-ab7f-b8a73e5b8f8e",
"adf0cd4c-3072-4ecf-9aa7-ecd5580c31ae"
],
"tag": "tag2",
"count": {
"low": 43,
"high": 0
}
}
];
const list2 = [{
"id": "5cca1dbc-dd5c-498f-8f83-735062c05240",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}],
"topics": [{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
},
{
"id": "fb420746-4d11-4d2e-ab7f-b8a73e5b8f8e",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}],
"topics": [{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
},
{
"id": "efde2bc9-018b-49c1-9c01-a4eda9817a33",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}],
"topics": [{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
}
];
var result1 = [];
for (let item of list1) {
let details = list2.filter(l2 => item.id.includes(l2.id));
if (details.length > 0) {
result1.push({
tag: item.tag,
count: item.count,
details: details
});
}
}
console.log(result1);
var result2 = list1.map(l1 => {
return {
tag: l1.tag,
count: l1.count,
details: list2.filter(l2 => l1.id.includes(l2.id))
};
});
console.log(result2);
You can use array.forEach,
First you need to take list1 and loop through each item, inside each item you have property called id, which is again a collection of array. you need to do a foreach with the id and check with the list2 and once the list2.id matches with the id of list 1 . it should push an object of your required output.
I hope the below code will solve the issue.
const list1 = [
{
"id": [
"5cca1dbc-dd5c-498f-8f83-735062c05240",
"2a10c30a-7c3a-4081-8246-9d37e19c2d6f",
"3128f36c-1c79-4301-b08f-e0182c256c03"
],
"tag": "tag1",
"count": {
"low": 53,
"high": 0
}
},
{
"id": [
"510019af-1728-4628-9019-343cd3c1b3e1",
"fb420746-4d11-4d2e-ab7f-b8a73e5b8f8e",
"adf0cd4c-3072-4ecf-9aa7-ecd5580c31ae"
],
"tag": "tag2",
"count": {
"low": 43,
"high": 0
}
}
]
const list2 = [
{
"id": "5cca1dbc-dd5c-498f-8f83-735062c05240",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [
{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}
],
"topics": [
{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
},
{
"id": "fb420746-4d11-4d2e-ab7f-b8a73e5b8f8e",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [
{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}
],
"topics": [
{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
},
{
"id": "efde2bc9-018b-49c1-9c01-a4eda9817a33",
"createdDate": "2017-10-08T22:40:33.020Z",
"modifiedDate": "2017-10-08T22:40:33.020Z",
"title": "Good morning! #tag1",
"text": " ",
"media": [
{
"id": "1f8c564c-91f1-457c-b4c1-0820c03861b4",
"metadata": {
"mimetype": "image/jpeg",
"imageHeight": 400,
"imageWidth": 300
}
}
],
"topics": [
{
"topicId": "22a96a83-def3-4981-bc91-9277464b7105"
},
{
"name": "Fashion",
"topicId": "6d4caea2-8387-42f3-977d-06a4bb063c44"
}
],
"language": null,
"sourceId": "d25205ca-2ef308261113",
}
]
var arr = []
list1.forEach(l1I => {
l1I.id.forEach(eID => list2.forEach(l2I => {
if(l2I.id === eID){
var obj = {}
obj["details"] = l2I;
obj["tag"] = l1I.tag;
obj["count"] = l1I.count;
arr.push(obj);
}
}))
})
console.log("output", arr)
Thank you so much for your responses,
I could solve it that day by this:
const responseValueList = {};
const hashtagsList = [];
for (const responseRow of list1) {
const obj = {};
obj.hashtagName = responseRow.hashtag;
obj.hashtagCount = responseRow.count;
const rateableList = []
for (const responseSectionTwo of list2) {
if (responseRow.id.includes(responseSectionTwo.id)) {
rateableList.push(responseSectionTwo);
}
}
obj.hashtagItems = rateableList;
hashtagsList.push(obj);
}
Thanks again

My Alexa Skill is giving me a difficult error, which I do not know the source of

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

Flatten nested json array to simple array in javascript(remove nesting)

I want to flatten my json nested array object to flat array
Both key and value pair should be dynamic as per the user input array
I tried to code myself but I am not much familiar with JavaScript function to do concat, push or other funtions.
Input:
{
"ReportID": "ProfitAndLoss",
"ReportName": "Profit and Loss",
"ReportType": 7,
"ReportTitles": [
"Profit & Loss",
"Clearlight Saunas Australia Pty Ltd",
"1 May 2017 to 31 May 2017"
],
"ReportDate": "17 May 2017",
"UpdatedDateUTC": "2017-05-17T05:52:23.414Z",
"Attributes": null,
"Fields": [],
"Rows": [
{
"RowType": "Header",
"Cells": [
{
"Value": "",
"Attributes": null
},
{
"Value": "31 May 17",
"Attributes": null
}
],
"Title": null,
"Rows": null
},
{
"RowType": "Section",
"Cells": null,
"Title": "Income",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Curve Dome Sauna",
"Attributes": [
{
"Value": "a76bacdc-a411-4924-9860-7c8b1bf36e5b",
"Id": "account"
}
]
},
{
"Value": "6725.46",
"Attributes": [
{
"Value": "a76bacdc-a411-4924-9860-7c8b1bf36e5b",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "Row",
"Cells": [
{
"Value": "Essential Sauna Sales",
"Attributes": [
{
"Value": "b2544842-1e51-4c08-80bc-7077f01a8657",
"Id": "account"
}
]
},
{
"Value": "21359.09",
"Attributes": [
{
"Value": "b2544842-1e51-4c08-80bc-7077f01a8657",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "Row",
"Cells": [
{
"Value": "Premier Sauna Sales",
"Attributes": [
{
"Value": "7f5bb82f-f488-441e-b578-c3e6d16829f0",
"Id": "account"
}
]
},
{
"Value": "19088.18",
"Attributes": [
{
"Value": "7f5bb82f-f488-441e-b578-c3e6d16829f0",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "Row",
"Cells": [
{
"Value": "Revenue - Installation ",
"Attributes": [
{
"Value": "e4985303-4ce7-4162-9ed3-e9a7799b5584",
"Id": "account"
}
]
},
{
"Value": "636.36",
"Attributes": [
{
"Value": "e4985303-4ce7-4162-9ed3-e9a7799b5584",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "Row",
"Cells": [
{
"Value": "Sanctuary sauna sale",
"Attributes": [
{
"Value": "90bda37d-e484-494c-8ad5-dd012f6acb56",
"Id": "account"
}
]
},
{
"Value": "26244.55",
"Attributes": [
{
"Value": "90bda37d-e484-494c-8ad5-dd012f6acb56",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "Row",
"Cells": [
{
"Value": "Sauna cover sale",
"Attributes": [
{
"Value": "5a1aa34f-9acb-4154-8d4c-bb7e56a16cc8",
"Id": "account"
}
]
},
{
"Value": "727.27",
"Attributes": [
{
"Value": "5a1aa34f-9acb-4154-8d4c-bb7e56a16cc8",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "SummaryRow",
"Cells": [
{
"Value": "Total Income",
"Attributes": null
},
{
"Value": "74780.91",
"Attributes": null
}
],
"Title": null,
"Rows": null
}
]
},
{
"RowType": "Section",
"Cells": null,
"Title": "",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Gross Profit",
"Attributes": null
},
{
"Value": "74780.91",
"Attributes": null
}
],
"Title": null,
"Rows": null
}
]
},
{
"RowType": "Section",
"Cells": null,
"Title": "Plus Other Income",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Sauna Sale to Clearlight NZ Ltd",
"Attributes": [
{
"Value": "12eca2ea-00ff-4f1a-9187-bd3faaf15eae",
"Id": "account"
}
]
},
{
"Value": "1309.09",
"Attributes": [
{
"Value": "12eca2ea-00ff-4f1a-9187-bd3faaf15eae",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "SummaryRow",
"Cells": [
{
"Value": "Total Other Income",
"Attributes": null
},
{
"Value": "1309.09",
"Attributes": null
}
],
"Title": null,
"Rows": null
}
]
},
{
"RowType": "Section",
"Cells": null,
"Title": "Less Operating Expenses",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Bank Fees",
"Attributes": [
{
"Value": "1ee9c97a-5707-4289-9d40-fa25d2f087d3",
"Id": "account"
}
]
},
{
"Value": "503.54",
"Attributes": [
{
"Value": "1ee9c97a-5707-4289-9d40-fa25d2f087d3",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "Row",
"Cells": [
{
"Value": "Sauna Storage",
"Attributes": [
{
"Value": "f3813ca9-9a0f-4c31-8afb-a1f9af61ca9a",
"Id": "account"
}
]
},
{
"Value": "670.00",
"Attributes": [
{
"Value": "f3813ca9-9a0f-4c31-8afb-a1f9af61ca9a",
"Id": "account"
}
]
}
],
"Title": null,
"Rows": null
},
{
"RowType": "SummaryRow",
"Cells": [
{
"Value": "Total Operating Expenses",
"Attributes": null
},
{
"Value": "1173.54",
"Attributes": null
}
],
"Title": null,
"Rows": null
}
]
},
{
"RowType": "Section",
"Cells": null,
"Title": "",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Net Profit",
"Attributes": null
},
{
"Value": "74916.46",
"Attributes": null
}
],
"Title": null,
"Rows": null
}
]
}
]
}
This is the desired output i want:
[
{
"ReportID": "ProfitAndLoss",
"ReportName": "Profit and Loss",
"ReportType": "7",
"ReportTitles": "Profit & Loss",
"ReportDate": "17 May 2017",
"UpdatedDateUTC": "2017-05-17T05:52:23.414Z",
"Attributes": null,
"Rows__RowType": "Header",
"Rows__Cells": "",
"Rows__Cells____Value": "",
"Rows__Cells____Attributes": null,
"Rows__Title": null,
"Rows__Rows____RowType": "",
"Rows__Rows____Cells__Value": "",
"Rows__Rows____Cells__Attributes": "",
"Rows__Rows____Cells__Attributes____Value": "",
"Rows__Rows____Cells__Attributes____Id": "",
"Rows__Rows____Title": "",
"Rows__Rows____Rows": "",
"Rows__Rows": null
},
{
"ReportID": "",
"ReportName": "",
"ReportType": "",
"ReportTitles": "Clearlight Saunas Australia Pty Ltd",
"ReportDate": "",
"UpdatedDateUTC": "",
"Attributes": "",
"Rows__RowType": "",
"Rows__Cells": "",
"Rows__Cells____Value": "31 May 17",
"Rows__Cells____Attributes": null,
"Rows__Title": "",
"Rows__Rows____RowType": "",
"Rows__Rows____Cells__Value": "",
"Rows__Rows____Cells__Attributes": "",
"Rows__Rows____Cells__Attributes____Value": "",
"Rows__Rows____Cells__Attributes____Id": "",
"Rows__Rows____Title": "",
"Rows__Rows____Rows": "",
"Rows__Rows": ""
},
{
"ReportID": "",
"ReportName": "",
"ReportType": "",
"ReportTitles": "1 May 2017 to 31 May 2017",
"ReportDate": "",
"UpdatedDateUTC": "",
"Attributes": "",
"Rows__RowType": "Section",
"Rows__Cells": null,
"Rows__Cells____Value": "",
"Rows__Cells____Attributes": "",
"Rows__Title": "Income",
"Rows__Rows____RowType": "Row",
"Rows__Rows____Cells__Value": "Curve Dome Sauna",
"Rows__Rows____Cells__Attributes": "",
"Rows__Rows____Cells__Attributes____Value": "a76bacdc-a411-4924-9860-7c8b1bf36e5b",
"Rows__Rows____Cells__Attributes____Id": "account",
"Rows__Rows____Title": null,
"Rows__Rows____Rows": null,
"Rows__Rows": ""
},
{
"ReportID": "",
"ReportName": "",
"ReportType": "",
"ReportTitles": "",
"ReportDate": "",
"UpdatedDateUTC": "",
"Attributes": "",
"Rows__RowType": "",
"Rows__Cells": "",
"Rows__Cells____Value": "",
"Rows__Cells____Attributes": "",
"Rows__Title": "",
"Rows__Rows____RowType": "",
"Rows__Rows____Cells__Value": "6725.46",
"Rows__Rows____Cells__Attributes": "",
"Rows__Rows____Cells__Attributes____Value": "a76bacdc-a411-4924-9860-7c8b1bf36e5b",
"Rows__Rows____Cells__Attributes____Id": "account",
"Rows__Rows____Title": "",
"Rows__Rows____Rows": "",
"Rows__Rows": ""
},
{
"ReportID": "",
"ReportName": "",
"ReportType": "",
"ReportTitles": "",
"ReportDate": "",
"UpdatedDateUTC": "",
"Attributes": "",
"Rows__RowType": "",
"Rows__Cells": "",
"Rows__Cells____Value": "",
"Rows__Cells____Attributes": "",
"Rows__Title": "",
"Rows__Rows____RowType": "Row",
"Rows__Rows____Cells__Value": "Essential Sauna Sales",
"Rows__Rows____Cells__Attributes": "",
"Rows__Rows____Cells__Attributes____Value": "b2544842-1e51-4c08-80bc-7077f01a8657",
"Rows__Rows____Cells__Attributes____Id": "account",
"Rows__Rows____Title": null,
"Rows__Rows____Rows": null,
"Rows__Rows": ""
},
{
"ReportID": "",
"ReportName": "",
"ReportType": "",
"ReportTitles": "",
"ReportDate": "",
"UpdatedDateUTC": "",
"Attributes": "",
"Rows__RowType": "",
"Rows__Cells": "",
"Rows__Cells____Value": "",
"Rows__Cells____Attributes": "",
"Rows__Title": "",
"Rows__Rows____RowType": "",
"Rows__Rows____Cells__Value": "21359.09",
"Rows__Rows____Cells__Attributes": "",
"Rows__Rows____Cells__Attributes____Value": "b2544842-1e51-4c08-80bc-7077f01a8657",
"Rows__Rows____Cells__Attributes____Id": "account",
"Rows__Rows____Title": "",
"Rows__Rows____Rows": "",
"Rows__Rows": ""
}]
You can store this json in a variable and make use of something like
JSON.parse(variable_name);
After this it's in the form of an array and you can easily loop through it
Hope this helps!

Categories