# Jsonata chain operator giving different results

**URL:** <https://discourse.nodered.org/t/jsonata-chain-operator-giving-different-results/76583>\
**Category:** General\
**Tags:** jsonata\
**Created:** [15 March 2023 09:58 UTC](https://discourse.nodered.org/t/jsonata-chain-operator-giving-different-results/76583 "2023-03-15T09:58:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shimbone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shimbone/32/24815_2.png) [@shimbone](https://discourse.nodered.org/u/shimbone)\
**Post date:** [15 March 2023 09:58 UTC](https://discourse.nodered.org/t/jsonata-chain-operator-giving-different-results/76583/1 "2023-03-15T09:58:34Z")

</div>

Given some JSON:

```auto
{
  "A": 1,
  "B" : 2,
  "C": 3
}

```

I'd expect this Jasonata statement` $spread($)[*=2]` to gives these results (which it does indeed):

```auto
 {
   "B": 2
 }

```

But when I use what I believe to be semantically the same statement but use the chain operator: `$~>$spread()[*=2]` it gives the results:

```auto
[
  {
    "A": 1
  },
  {
    "B": 2
  },
  {
    "C": 3
  }
]

```

Could anyone explain why Jsonata processes those two statements which in my estimation should yield identical results, but are handled so differently? Is there something I don't understand about the chain operator?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [15 March 2023 16:51 UTC](https://discourse.nodered.org/t/jsonata-chain-operator-giving-different-results/76583/2 "2023-03-15T16:51:31Z")

</div>

The chain parts need to be in parentheses  
e.g

```auto
($~>$spread())[*=2]

```

[edit] removed typo

---

<div class="post-metadata">

**Author:** ![shimbone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shimbone/32/24815_2.png) [@shimbone](https://discourse.nodered.org/u/shimbone)\
**Post date:** [15 March 2023 18:21 UTC](https://discourse.nodered.org/t/jsonata-chain-operator-giving-different-results/76583/3 "2023-03-15T18:21:49Z")

</div>

Thank you! Great insight! Do you understand why? Is it an order of operations problem?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [15 March 2023 18:36 UTC](https://discourse.nodered.org/t/jsonata-chain-operator-giving-different-results/76583/4 "2023-03-15T18:36:55Z")

</div>

I believe the spread is applying the filter to each property of the object, rather than the finished array.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 March 2023 18:37 UTC](https://discourse.nodered.org/t/jsonata-chain-operator-giving-different-results/76583/5 "2023-03-29T18:37:04Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
