Closed itzmearun closed 6 years ago
@#need alasql query to access the inner json array values
Please reopen this issue when you can provide an example of the desired output and examples of what you have tried until now.
This is the below query i tried to export to excel from the above json values
need to access the StrCount from promos array for each promoID for each reservationId
currently exporting to excel is only exporting first level. i,e no values are getting exported from promos and locations
alasql('SEARCH / AS @temp \
promos AS @b \
locations AS @c \
RETURN(@temp ->reservationId AS Reservation_ID, @temp ->reservationName AS Reservation_Name, @temp ->startDate AS Reservation_Start_Date, \
@temp ->endDate AS Reservation_End_Date, \
@b->StrCount as StoreCount @b->promoId as PromoId @b->promoName as PromoName \
@c->crossAdjacencyDesc AS crsossAdj
) INTO XLSX("' + outputFile + '",{headers:true})\
FROM ?',[$scope.data]);
Please reopen this issue when you can provide an example of the desired output too.
I am not getting how to reopen this issue agian which you have closed @mathiasrw
Please provide the input as json and expected output as json
in the above excel promostore count is not priniting
the input is json what is shared in the example i want to traverse and export the values to excel
I need a alasql query which can traverse this json and parse the value.
suppose if i want to export crossAdjacencyDesc value to excel from location array in the promos array which is in the reservation array. as shown in example how can i parse that with alasql query?
The code provided in the first input is not valid json. Please provide valid json.
Use this if in doubt: https://jsonlint.com
0:
PromoStrCount:8
endDate:"07/08/2014"
promos:(3) [{…}, {…}, {…}]
0:
StrCount:4
locations:(4) [{…}, {…}, {…}, {…}]
0:{fixtureId: 95580, storeNbr: 3, storeName: "store name", reservationId: 61, reservationName: "reservation name", …}
0:
crossAdjacencyDesc:"FLOORING"
first_date_Available:null
fixtureEffDate:null
fixtureEndDate:null
fixtureId:95580
height:60
storeNbr:3
t1573FixtureId:0
1:{fixtureId: 96209, storeNbr: 56, storeName: "LOWE'S OF NORWALK, CA ", reservationId: 61, reservationName: "reservation name", …}
2:{fixtureId: 99410, storeNbr: 598, storeName: "LOWE'S OF GREENVILLE, NC ", reservationId: 61, reservationName: "reservation name", …}
3:{fixtureId: 89888, storeNbr: 1700, storeName: "LOWE'S OF N. FONTANA, CA ", reservationId: 61, reservationName: "reservation name", …}
promoId:73525
promoName:"promo name"
promoendDate:"02/09/2014"
promostartDate:"02/05/2014"
1:{promoId: 78414, promoName: "promo name ", promostartDate: "02/10/2014", promoendDate: "07/08/2014", StrCount: 2, …}
2:{promoId: 78415, promoName: "promo name ", promostartDate: "02/10/2014", promoendDate: "07/08/2014", StrCount: 2, …}
reservationId:61
reservationName:"reservation name "
startDate:"02/05/2014"
From jsonlint.com
Error: Parse error on line 1: 0: PromoStrCount: 8 -^ Expecting 'EOF', '}', ',', ']', got ':'
{
"PromoStrCount": 8,
"endDate": "07/08/2018",
"reservation": [{
"reservationId": 61,
"reservationName": "FLEX ECRT FLOORING 1 (VALUE RUGS)",
"startDate": "02/05/2018",
"promos": [{
"StrCount": 4,
"promoId": 73525,
"promoName": "0218EC*FLEX ECRT FLOORING 1 (VALUE RUGS)",
"promoendDate": "02/09/2018",
"promostartDate": "02/05/2018"
},
{
"StrCount": 5,
"promoId": 73526,
"promoName": "flooring",
"promoendDate": "03/08/2017",
"promostartDate": "03/06/2017"
}
]
}]
}
how to access the inner value StrCount which is in nested array in Json
the query what I have written is this to parse the json
alasql('SEARCH / AS @a \
promos AS @b \
RETURN(@a->reservationId AS Reservation_ID, @a->reservationName AS Reservation_Name, @a->startDate AS Reservation_Start_Date, @a->endDate AS Reservation_End_Date, \
@b->StrCount as Promostrcount \
) INTO XLSX("' + outputFile + '",{headers:true})\
FROM ?',[$scope.data]);
Please provide expected json output.
expected output: I want to export the StrCount 4 and StrCount 5 respectively for both promoId 73525 and promoId 73526 for reservationId 64.
basically i want a query to traverse the inner json array values so that i can export those values to excel
Please provide an example of the exact json output you are looking for from the input
{
"PromoStrCount": 8,
"endDate": "07/08/2018",
"reservation": [{
"reservationId": 61,
"reservationName": "FLEX ECRT FLOORING 1 (VALUE RUGS)",
"startDate": "02/05/2018",
"promos": [{
"StrCount": 4,
"promoId": 73525,
"promoName": "0218EC*FLEX ECRT FLOORING 1 (VALUE RUGS)",
"promoendDate": "02/09/2018",
"promostartDate": "02/05/2018"
},
{
"StrCount": 5,
"promoId": 73526,
"promoName": "flooring",
"promoendDate": "03/08/2017",
"promostartDate": "03/06/2017"
}
]
}]
}
I dont need an json output i want the content which is present in the above json should be exported to an excel file using alasql query. The query what i have written is only capable of exporting the first level of the json.
The inner level values in the promos i am not able to travarse through my query. so help me out with a query to traverse so that i can export whatever content i need to.
suppose i need to export promoName from above json for both promoid 73525 and 73526 for reservationId 61 how the query should be written?
Please provide a valid json that represents the data you wish to export to excel.
{
"reserv": [{
"endDate": "07 / 08 / 2018",
"promoId": 73525,
"promoName": "promo name",
"promoStoreCount": 4,
"promodisplayDesc": 20142014,
"reservationDesc": "dsfds ",
"reservationId": 61,
"reservationName": "reseervation name",
"startDate": "02 / 05 / 2018",
"statusCode": 2
},
{
"endDate": "07 / 08 / 2018",
"promoId": 73526,
"promoName": "promo name",
"promoStoreCount": 8,
"promodisplayDesc": 20142014,
"reservationDesc": "dsfds ",
"reservationId": 61,
"reservationName": "reseervation name",
"startDate": "02 / 05 / 2018",
"statusCode": 3
},
{
"endDate": "05 / 04 / 2018",
"promoId": 73527,
"promoName": "promo name",
"promoStoreCount": 5,
"promodisplayDesc": 20142014,
"reservationDesc": "dsfds ",
"reservationId": 61,
"reservationName": "reseervation name",
"startDate": "05 / 08 / 2018",
"statusCode": 3
}
]
}
There is no statusCode
in the original input, so this can not be done.
{
"reserv": [{
"endDate": "07 / 08 / 2018",
"promoId": 73525,
"promoName": "promo name",
"promoStoreCount": 4,
"promodisplayDesc": 20142014,
"reservationDesc": "dsfds ",
"reservationId": 61,
"reservationName": "reseervation name",
"startDate": "02 / 05 / 2018"
},
{
"endDate": "07 / 08 / 2018",
"promoId": 73526,
"promoName": "promo name",
"promoStoreCount": 8,
"promodisplayDesc": 20142014,
"reservationDesc": "dsfds ",
"reservationId": 61,
"reservationName": "reseervation name",
"startDate": "02 / 05 / 2018"
},
{
"endDate": "05 / 04 / 2018",
"promoId": 73527,
"promoName": "promo name",
"promoStoreCount": 5,
"promodisplayDesc": 20142014,
"reservationDesc": "dsfds ",
"reservationId": 61,
"reservationName": "reseervation name",
"startDate": "05 / 08 / 2018"
}
]
}
ok i dont need that filed statusCode in my output json
In the input data you have provided there is no value of 05 / 04 / 2018
.
Please provide valid json of input and desired output.
This issue have been solved
below is the snippet to replicate... Need a query in alasql to query the nested values in the array to export in xls.
I need to fetch the below data