Skip to content

Implement support of spread operator #745

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ericleib
Copy link

This Pull Request adds support of the spread operator ... in the Jsonata syntax.

The implementation works the same way as in Javascript:

{
   "a": "hello",
   "b": "world",
   ...foo
}

This copies the key/value pairs from object foo to a new object, in this case potentially overriding properties a and b. Conversely, if a and b were added AFTER foo, then their values would override the a and b entries of foo.

Please let me know if this is something that the community would be interested in. In my case (an avid Jsonata user), this feature would make a big difference.

@andrew-coleman
Copy link
Member

Thank you for raising this.

On the face of it, this looks like a great proposal. What's concerning me though is the implied order of execution of the items within the object. Although not a problem for this Javascript implementation, it could be a problem for other implementations. Take a look at this issue for reference. Although that issue was only relating to the test suite, I think this proposal would bring it into the language itself.

I'm not saying that a feature like this is not possible, but we need to be very mindful of this potential problem.

@ericleib
Copy link
Author

Thank you for looking into it!

I understand your concern. It does bring a change to the language. In fact when implementing it, I could see the potential inconsistency of behavior with this error "Multiple key definitions evaluate to same key" (which prevents any key overriding mechanism).

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

Successfully merging this pull request may close these issues.

2 participants