How to reassign keys in JSON map

Hello

I am just learning how to use flows and unfortunately new to FQL as well as the automated AI feature is not working right now.

I need help figuring out how to reassign the keys of a json map from 0,1,2 to the word item, so item1, item2, item3.

{
    0 : "test"
    1: "test2"
    2: "test3"
}
{
    "item1" : "test"
    "item2" : "test2"
    "item3" : "test3"
}

Really appreciate any help :slight_smile:

Hey @legiuffre

Welcome to the forums!

Based on what you provided i’m assuming you have a list of strings and you want to turn it into a JSON object.

This can be accomplished by using the $map function to add an auto-numbered key to every object and then using the $merge function to turn this list of JSON objects into a single JSON object.

Here’s the FQL:

$merge($map(list, fn ($v,$i) {
    {"item" & ($i+1) : $v}
}))

In this function, $v is the value (test1) and $i is the index (starting at 0)

And an image:

Let me know if you have any questions. :slightly_smiling_face:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.