Skip to content

Weird behaviour with parent operator and array constructors #645

@mikhail-barg

Description

@mikhail-barg

While implementing the parent operator in my .Net Jsonata port, I stumbled upon the following test in the suite. It says that applying the query

Account.Order.Product.[`Product Name`, %.OrderID]

to the Invoice dataset should result in a flat array,

[
  "Bowler Hat",
  "order103",
  "Trilby hat",
  "order103",
  "Bowler Hat",
  "order104",
  "Cloak",
  "order104"
]

which indeed it does: https://try.jsonata.org/3IY-yuZkE

But why? Isn't the braces here are the explicit array constructor? Consider changing the query to one without parent operator, e.g.:

Account.Order.Product.[`Product Name`, SKU]

This would result in a nested array:

[
  [
    "Bowler Hat",
    "0406654608"
  ],
  [
    "Trilby hat",
    "0406634348"
  ],
  [
    "Bowler Hat",
    "040657863"
  ],
  [
    "Cloak",
    "0406654603"
  ]
]

Aren't the queries are just the same in the aspect of result structure?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions