Accessing object property by name as string

USECASE:
In postman flows, i am manipulating datasets fetched from a third party.
The naming of these props, perhaps related to the xml source-type are not good.
Every prop name starts with “g:”

Example:
[{
“g:id”: “someId1”,
“g:title”: “someTitle1”,
“g:color”: “someColor1”
},
“g:id”: “someId2”,
“g:title”: “someTitle2”,
“g:color”: “someColor2”
}
]
etc…

using the [select block] works fine, also selecting inside an [evaluate block] works.

However for doing data manipulation on an array of objects [for block] takes too long so I would like to avoid it.

I would like to do something like the following inside a evaluate block:
$filter(objectList, fn ($v) {$v[“g:color”] = “someColor1”})

It seems this colon character is causing the issue.

Someone else had a similar problem with special characters in the evaluate block, and using backticks instead of quotes appeared to resolve their issue.

Something for you to try.

Unfortunately backticks aren’t working either, unless it needs to be combined with some other quotation marks.

So far I’ve tried these " - ’ - ´ - `

No luck sadly :confused:

I don’t know which language this FQL stuff is modeled after, so guessing is a bit hard :stuck_out_tongue:

This appears to be a bug in the FQL not allowing you to name keys with "" but this will work:

objectList[`g:color`="someColor2"]

The learning center has some useful FQL filtering examples.

And a sneak peek at something launching at Post/Con, you will be able to use TypeScript instead of FQL where desired (as objectList.filter(v => v["g:color"] == "someColor1")… Stay tuned.

Make sure your quotes are ASCII quotes.

Great!

This worked, and typescript sounds fantastic!

Copying text from this page made some strange quotation marks so thanks for mentioning that!

Follow-up questions!
if i want to access this property inside a map function, is that possible in some way as well?

I also tried the following without getting it to work:

Try this, it worked for me. I admit we need to fix up some of these quirks.

$filter(list, fn($item) { 
    $item."g:color" = color
})

This worked, thanks a bunch! I suppose ill get into the habit of always enclosing key names with quotation double marks.