Skip to content

Context variabe binding breaks when joining empty arrays or the join results in an empty result #770

@makeeno

Description

@makeeno

Let's consider the following input:

{
  "equipments": [
    {
      "type": "Type A",
      "name": "Name A"
    },
    {
      "type": "Type A",
      "name": "Name A2"
    },
    {
      "type": "Type B",
      "name": "Name B"
    }
  ],
  "data": [
    {
      "id": "0001",
      "equipmentName": "Name A"
    },
    {
      "id": "0001",
      "equipmentName": "Name A2",
      "value": 1
    },
    {
      "id": "0001",
      "equipmentName": "Name B",
      "value": 2
    },
    {
      "id": "0002",
      "equipmentName": "Name A",
      "value": 3
    },
    {
      "id": "0003",
      "equipmentName": "Name A2",
      "value": 3
    }
  ]
}

and the following Jsonata:

equipments@$equipments.data
  [$equipments.type = "Type A" and $equipments.name = equipmentName] {
  id: {
    "equipmentNames": equipmentName[]
  }
}

which correctly results in

{
  "0001": {
    "equipmentNames": [
      "Name A",
      "Name A2"
    ]
  },
  "0002": {
    "equipmentNames": [
      "Name A"
    ]
  },
  "0003": {
    "equipmentNames": [
      "Name A2"
    ]
  }
}

Now the issue is, if:

  • in the input equipments is empty or does not exist
  • or data is empty or does not exist
  • or the filter [ ... ] (e.g. by changing "Type A" into "Type C") returns an empty result

then the following error is thrown:

can't access property "@", c is undefined

It looks like a bug since the error message is not clear about what I did wrong.

I could add a . after the filter but this changes the result and messes up the grouping:

equipments@$equipments.data
  [$equipments.type = "Type A" and $equipments.name = equipmentName]. {
  id: {
    "equipmentNames": equipmentName[]
  }
}

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