Search code examples
jsonjsonata

Take a value 5 and convert it to json object


i should take a JSON value, like

{
  "cnt": 5
} 

and create JSON object from JSONata, like

{
  "1": 1,
  "2": 4,
  "3": 9,
  "4": 16,
  "5": 25,
}

I tried to do that, but i cant join two expressions correctly.

{
"" & [1..cnt] : [1..cnt].($*$)
}

and i get as a result:

{
  "[1,2,3,4,5]": [
    1,
    4,
    9,
    16,
    25
  ]
}

Can anybody help me with this(


Solution

  • Try [1..cnt]{$string($): $*$}

    See https://try.jsonata.org/SVapg4fzt