Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force nested arrays #399

Closed
markmelville opened this issue Jan 10, 2020 · 1 comment · Fixed by #405
Closed

Force nested arrays #399

markmelville opened this issue Jan 10, 2020 · 1 comment · Fixed by #405
Labels

Comments

@markmelville
Copy link
Contributor

I've had no luck figuring out this nuance. I'm trying to convert data to a timeseries format required by another system. It wants the data as an array of arrays like this: http://try.jsonata.org/BkKNErBxL
Input:

[
  {"epochSeconds":1578381600,"value": 3},
  {"epochSeconds":1578381700,"value": 5}
]

Expression: $.[value,epochSeconds]
Result:

[
  [3,1578381600],
  [5,1578381700]
]

This is correct, but when there is only one item in the input array the result gets flattened.
Input:

[
  {"epochSeconds":1578381600,"value": 3}
]

Desired Output:

[
  [3,1578381600]
]

What I'm getting:

[
  3,
  1578381600
]

Is there some way to force an outer enclosing array when there is only one data point? TIA

@andrew-coleman
Copy link
Member

It's a good question. I would have expected the following expression to work:

$.[value,epochSeconds][]

I.e. The result is a singleton sequence containing an array value. The [] should turn the sequence into a JSON array.

But this is clearly not working. I'll mark this as a bug and endeavour to fix it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants