PLUCK question. Getting array of prices out of the json

Hi there

I am trying to use PLUCK from the data collection I get as a json, in particular the prices.

What am I doing wrong?

thanks for the help
Andreas

PS: And the follow up question would be, how I can get them to be summed up

Hi,

Hmm there might be a couple of things wrong here, is data.Travels1.name.fields an object, or a list of objects? PLUCK only works on a list of objects. Secondly, PLUCK creates a new list, in this case a list of all prices. An input’s label only takes a text type value, not a list of numbers type value.

As for the summing, if you have a list of objects that all have a property price, you can use PLUCK to create a list of only the prices (as you’re doing in that formula) and then add the formula SUM to sum them all up.

Hi @Cecilia thanks for your help.

Travel1 is a collection of data records I get from google firestore db as a json. As I understand this is a list of objects, isn’t it, everyone with a price, which I like to have summed up.

The structure of the json is like this:

[
{
“name”: “projects/travel-journey-for-shuttlers/databases/(default)/documents/travels/510z0nhaP3oHXUjoYZ36”,
“fields”: {
“towork”: {
“booleanValue”: true
},
“price”: {
“integerValue”: “3”
},
“number”: {
“stringValue”: “33”
},
“from”: {
“stringValue”: “Basel Badischer Bahnhof”
},
“type”: {
“stringValue”: “Flight”
},
“wherebooked”: {
“stringValue”: “”
},
“to”: {
“stringValue”: “Frankfurt Flughafen”
},
“date”: {
“timestampValue”: “2021-10-27T22:00:00Z”
}
},
“createTime”: “2021-10-20T06:48:13.707490Z”,
“updateTime”: “2021-10-20T07:49:05.057418Z”
},
{
“name”: “projects/travel-journey-for-shuttlers/databases/(default)/documents/travels/BaY6nmTCCYBHoeY2F4Hk”,
“fields”: {
“wherebooked”: {
“stringValue”: “”
},
“from”: {
“stringValue”: “Lörrach”
},
“to”: {
“stringValue”: “Basel Badischer Bahnhof”
},
“price”: {
“integerValue”: “4”
},
“towork”: {
“booleanValue”: true
},
“date”: {
“timestampValue”: “2021-10-20T22:00:00Z”
},
“number”: {
“stringValue”: “738”
},
“type”: {
“stringValue”: “Local”
}
},
“createTime”: “2021-10-20T06:44:09.079629Z”,
“updateTime”: “2021-10-20T07:49:59.296282Z”
},
{
“name”: “projects/travel-journey-for-shuttlers/databases/(default)/documents/travels/PKYDV1LuarJHv2FoytX1”,
“fields”: {
“type”: {
“stringValue”: “Local”
},
“towork”: {
“booleanValue”: true
},
“date”: {
“timestampValue”: “2021-10-21T00:01:00Z”
},
“price”: {
“integerValue”: “2”
},
“from”: {
“stringValue”: “Lörrach”
},
“wherebooked”: {
“stringValue”: “DB”
},
“to”: {
“stringValue”: “Basel Badischer Bahnhof”
},
“number”: {
“stringValue”: “10”
}
},
“createTime”: “2021-10-20T20:48:05.885875Z”,
“updateTime”: “2021-10-20T20:48:05.885875Z”
},
{
“name”: “projects/travel-journey-for-shuttlers/databases/(default)/documents/travels/uBZNam5x2C2p3RTogq2O”,
“fields”: {
“date”: {
“timestampValue”: “2021-12-01T00:01:00Z”
},
“towork”: {
“booleanValue”: true
},
“to”: {
“stringValue”: “ghgh”
},
“number”: {
“stringValue”: “tttt”
},
“price”: {
“integerValue”: “25”
},
“type”: {
“stringValue”: “2”
},
“wherebooked”: {
“stringValue”: “dvkbh”
},
“from”: {
“stringValue”: “gggh”
}
},
“createTime”: “2021-10-20T19:25:51.815144Z”,
“updateTime”: “2021-10-20T19:25:51.815144Z”
}
]

Thanks for your help
Andreas

Anyone who can help?

Hi, have you tried SUM_BY_KEY(data.Travels1…, “price”) function?

Hi @Yury_Gunko thanks for your help. I did not manage sadly, but maybe I need to find a tutor for it. Maybe my problem is that I don’t really know to “access” the Travels1 correctly. It is a json and comes from firebase.

Hi, a closer look at your task pinned me down(. I think, formula should be: SUM_BY_KEY(data.Travels1, “fields.price.integerValue”). But, as far as I understand, the “integerValue” property of the JSON returns string value (ex. “3”):
“price”: {
“integerValue”: “3”
}.
So, I think, the SUM_BY_KEY function does not suitable for the task.

Hi @Yury_Gunko

Now the json is returning a real doubleValue, no more “String integerValue”.

Now I just have the problem of accessing it directly, hence I don’t understand the json denotation correctly I assume.

Above you’ll see the json, it’s still the same but with doubleValue. So how would the correct syntax in the SUM_BY_KEY be to get the result? I tried several things but I am unable.

Thanks for your help
Andreas

PS: I would really love to read more about the syntax. Appgyver talks in tutorial videos of “dot syntax” but there seems to be no such thing.