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

Why are we not returning an array from $map if the input array is one in length? #512

Open
aakash-verma-aurea opened this issue Apr 12, 2021 · 4 comments

Comments

@aakash-verma-aurea
Copy link

Please check the difference between https://try.jsonata.org/Rf8UI_TMy and https://try.jsonata.org/0L_oYffzT

@rrameshkumar76
Copy link

This is answered here #462 (comment)

@aakash-verma-aurea
Copy link
Author

Thanks, @rrameshkumar76 but it's just acknowledged with a weird workaround. I have no clue why the API built this way which seems very inconsistent to me. It just causes pain for all new developers who waste time debugging and looking it up. I suggest we should have a consistent return type.

@carlosnturing
Copy link

I have created a PR here to at least add a warning in the documentation.

The warning suggests the workaround from this issue comment.

I think this is an unexpected behavior for anyone that has worked with map outside of JSONata.

@markmelville
Copy link
Contributor

markmelville commented Dec 16, 2024

As explained here, the [] syntax was added to allow array behavior instead of the default sequence behavior. I think it's a bit reductive to call it a workaround, even though it's technically true. There's history and complexity to the issue and it would be problematic to just change default behavior. There would be blowback. I suggest some kind of compilation flag, like regex has, to enable the array behavior everywhere.

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

No branches or pull requests

4 participants