2

Lets say I have a data structure that looks like this:

{ a: [ 1, 2, 3] }

I want to return 'a' wrapped in an array:

[ [ 1, 2, 3] ]

Is there any way to do this in JSONata?

Intuitively you would try [a], which you would expect to return the array as [[1,2,3]], but this returns [1,2,3], because of array singleton equivalence in JSONata.

Anders E. Andersen
  • 1,635
  • 2
  • 14
  • 20

1 Answers1

4

You can try the below query

[[a]] - wrapping a within 2 set of square brackets

Since 'a' returns

 1, 2, 3 

[[a]] returns

[[1,2,3]]
  • Hi, I already tried this. I edited my question to stress this point. It doesn't work because of array singleton equivalence will cause the wrapping array to be removed. – Anders E. Andersen May 04 '19 at 18:33
  • Hmm.. DIdn't you write `[a]` in your answer initially? That is what I tried. I see `[[a]]` does indeed work as expected. Rather unintuitive though. Can you make a minor edit to your reply, so I can change the vote and accept? Sorry for the confusion. – Anders E. Andersen May 04 '19 at 20:50